Gleam 1.0 Is Out! (I think I'm in love...)
Summary
TLDRGleam, a new programming language built on the Erlang VM, has released its first stable version, Gleam 1.0.0. Designed for type safety and concurrency, Gleam aims to simplify software development with a small, consistent language surface area. It offers robust static analysis, a practical type system, and a focus on developer productivity and sustainability. The language's features include immutability, pattern matching, and a unique approach to type definitions and function handling. Gleam's community-driven development and sponsorship model highlight the project's commitment to long-term support and growth.
Takeaways
- π Gleam 1.0.0 has been released, marking the first stable release of the language.
- π οΈ Gleam is built on the Erlang VM (BEAM), inheriting its benefits and focusing on type safety and a practical type system.
- π The language aims to make software development predictable, stress-free, and enjoyable, with a consistent and small surface area for easy learning.
- π Gleam emphasizes type safety, avoiding null values, implicit conversions, and exceptions, providing clear error messages.
- π It supports concurrency with ease, similar to Erlang and Elixir, making it suitable for building scalable systems.
- π§ Gleam's compiler serves as a programming assistant, aiding in refactoring and reducing the risk of breaking changes.
- π Gleam code can run on JavaScript runtimes, allowing for broader application possibilities, including in-browser execution.
- π The language includes a code formatter and language server, promoting a consistent coding style and improving developer experience.
- πΌ Version 1 signifies stability and readiness for production use, with a commitment to maintaining backward compatibility.
- π€ The Gleam community is actively contributing to the project, with a focus on impactful and meaningful development.
Q & A
What is Gleam and why is it significant?
-Gleam is a programming language designed for building typesafe systems that scale. It is significant because it is built on top of the Erlang VM (BEAM), which provides the same benefits as Elixir, but with a stronger focus on type safety and a practical type system.
What are the key features of Gleam's type system?
-Gleam's type system includes no null values, no exceptions, clear error messages, and a practical approach to type safety. It is inspired by languages like Elm, old Camo, and Rust, offering robust static analysis and a compiler that serves as a programming assistant.
How does Gleam handle concurrency?
-Gleam leverages the concurrency capabilities of the Erlang VM, allowing for easy implementation of concurrency with features like process spawning and message passing. This makes it suitable for building high-performance, concurrent systems.
What does Gleam's version 1.0.0 release signify?
-The release of Gleam 1.0.0 marks the first stable release of the language, indicating that it is now suitable for production use and that the developers will prioritize maintaining backward compatibility.
How does Gleam differ from other languages in terms of performance focus?
-While many modern languages focus on raw performance, Gleam emphasizes the importance of concurrency and the ability to handle multiple cores effectively. It aims to solve performance issues related to concurrency rather thanεηΊ―ηθΏ½ζ±θ―θ¨ηζ§θ‘ιεΊ¦.
What is the Gleam standard library and how does it relate to the V1 release?
-The Gleam standard library is a collection of core packages maintained by the Gleam team. It is set to receive an accompanying V1 release, ensuring that the standard library is compatible with the new version of the language.
How does Gleam support developer productivity and sustainability of the project?
-Gleam aims to improve developer productivity by continuously enhancing the language server, libraries, and developer experience. For project sustainability, Gleam relies on community contributions and financial support from sponsors like Fly, ensuring that the project can evolve without being limited by niche or unimportant tasks.
What are some of the language design principles that Gleam adheres to?
-Gleam adheres to principles like simplicity, consistency, and a small surface area, making it easy to learn and understand. It also prioritizes readability and maintainability of code, with a focus on having one way of doing things.
How does Gleam handle pattern matching and case expressions?
-Gleam uses pattern matching in its case expressions, allowing for concise and expressive code. It supports matching on various data structures like lists and tuples, and the compiler is smart enough to infer types and handle cases where certain arguments are not used.
What is the role of the Gleam community in the development of the language?
-The Gleam community plays a crucial role in the development of the language. The core team actively seeks contributions from the community, and the project's sustainability relies on the efforts of part-time volunteers and sponsors like Fly, who provide financial support.
Outlines
π Gleam Language Introduction
Gleam is a typesafe language built on the Erlang VM, offering the same benefits as Elixir but with a focus on type safety. It aims to make coding predictable, stress-free, and enjoyable. Gleam 1.0.0 has been released, marking a stable version of the language. It emphasizes type safety, clear error messages, and a practical type system. The language is designed to be easy to learn and understand, with a small surface area and a consistent approach to problem-solving.
π Gleam's Version 1 Features and Goals
Gleam 1.0 includes all public APIs, a compiler, build tools, a package manager, a code formatter, a language server, and support for WebAssembly and JavaScript bindings. The language server and code formatter are prioritized to improve developer experience. The Gleam standard library and community packages will also receive V1 updates. The focus for Gleam post-V1 is to enhance productivity and sustainability, with an emphasis on simplicity and avoiding breaking changes.
π€ Community and Financial Support for Gleam
Gleam is a community-driven project with a small team and part-time volunteers. The project emphasizes efficiency and meaningful contributions. The Gleam compiler and build tools are designed to be easy to contribute to. Financially, the project relies on sponsors like Fly, with the lead developer aiming to diversify funding sources. The goal is to ensure the project's sustainability and support for contributors.
π Gleam's Learning Resources and Features
Gleam offers a comprehensive language tour for beginners, showcasing its features like type inference, immutability, and pattern matching. The language includes a robust static type system, no null values, and no exceptions, ensuring full type checking. Gleam's standard library is well-developed, and the language supports features like emojis in variable names, type annotations, and blocks for scoped variables.
π Exploring Gleam's Functional Programming Aspects
Gleam supports higher-order functions, allowing functions to take other functions as arguments. It also has anonymous functions and a shorthand syntax for creating and calling functions inline. The language enforces camel case for function names and does not support function overloading, ensuring a single implementation for each function name. Gleam's pattern matching is powerful, allowing for specific and flexible matching of data structures.
π Gleam's Pattern Matching and Future Prospects
Gleam's pattern matching is sophisticated, allowing for matching complex data structures and opting out of certain cases. The language does not support function overloading, maintaining a single implementation per function name. The Gleam team is focused on improving the language's developer experience and sustainability, with plans to enhance the language server and libraries for real-world productivity. The project aims to avoid breaking changes and maintain simplicity as a core feature.
Mindmap
Keywords
π‘Gleam
π‘Type Safety
π‘Concurrent Programming
π‘Erlang VM (BEAM)
π‘Semantic Versioning
π‘Refactoring
π‘Web Frameworks
π‘Language Server Protocol (LSP)
π‘Community and Sustainability
π‘Pattern Matching
Highlights
Gleam is a friendly language for building typesafe systems that scale, built on top of the Elixir's BEAM runtime.
Gleam focuses more on type safety compared to Elixir, which is adding a type system.
Gleam 1.0.0 has been released, marking the first stable release of the language.
Gleam aims to make coding as predictable, stress-free, and enjoyable as possible with a consistent and easy-to-learn language design.
Gleam's type system is inspired by Elm, old Camo, and Rust, providing robust static analysis.
Gleam runs on the BEAM VM, which powers reliable and scalable systems like WhatsApp.
Gleam can also run on JavaScript, allowing for browser and mobile execution.
Gleam's V1 release includes public APIs, compiler, build tools, package manager, code formatter, language server, and compiler for WebAssembly APIs and JS bindings.
Gleam follows semantic versioning, ensuring backward compatibility and stability for production systems.
Gleam's design goals include making refactoring low risk and low stress.
Gleam's standard library and other packages will receive V1 releases to ensure a smooth transition for users.
Gleam is a community project with a small team, including full-time and part-time volunteers.
Gleam prioritizes developer experience and real-world productivity, focusing on improving the language server and libraries.
Gleam's sustainability relies on efficient efforts and impactful contributions from the community.
Gleam's creator, poor Lewis, is working full-time on the project thanks to support from sponsors like Fly.
Gleam's mascot, Lucy the starfish, represents the friendly nature of the language and community.
Gleam's learning resources include a language tour that compiles to JavaScript and runs in the browser.
Gleam enforces camel case for function names and has a simple and obvious syntax for public functions.
Gleam supports labeled arguments, making it easier to remember the order and purpose of function arguments.
Gleam has a robust static type system with no null, implicit conversions, or exceptions, ensuring full type checking.
Gleam's pattern matching allows for concise and maintainable code, with the compiler smart enough to optimize case expressions.
Gleam does not support function overloading, enforcing a single implementation for each function name and type combination.
Transcripts
gleam is a friendly language for
Building typesafe Systems that scale
this is a project I've been keeping an
eye on for a while largely because as an
Elixir Fanboy it's interesting gleam is
also built on top of the earling beam
runtime which means it gets a lot of the
same benefits in ecosystem that Elixir
has but it's Focus much more on type
safety and its type system whereas
alixir is adding a type system and super
super focused on the math side there
this is an alternative approach to
building on top of beam and it looks
very similar this code looks hilariously
similar to I was used to writing in
Elixir but it comes with a lot of the
type safety and other benefits that we
would expect it does have the same
piping functionality and behaviors it
has the threads and all the cool Spawn
tasking stuff that you can do in the
earling beam VM but it gives us type
safety as we do it here we see did you
mean name instead of Alias no null
values no exceptions clear error
messages and a practical type system
whether you're writing new code or
maintaining old code gleam is designed
to make your job as fun and stressfree
as possible why are we talking about
gleam today as I said I've been around
for a bit I've been keeping an eye on
this thing for even longer why today
well gleam version one is finally here
what is their version one release like
let's take a look today gleam 1.0.0 has
been released this is the first stable
release of the language more on what
that means later as well as a big
milestone for the ecosystem it's been a
long journey and I'm proud of both the
tech and the community that we've built
here with gleam thank you so much to
everyone who has taken part in any way
you've all contributed to the project
getting here in meaningful ways of all
sizes so what is gleam gleam is a
programming language that tries to make
your job as a writer and maintainer of
software systems as predictable
stressfree and enjoyable as possible the
language is consistent and has a small
surface area making it possible to learn
in an afternoon coupled with a lack of
magic and strong desires to have only
one way of doing things gleam is
typically easy to read and understand
reading and debugging code is more
difficult than writing new code so we
try to optimize for that I will say this
is very different from the direction
we've seen in other languages recently I
feel like all the languages people are
hyped about and talking about right now
are all in focused on performance and
that's great there are a lot of things
that need really good performance
especially in a world where javascript's
taken over way too much stuff when you
end up running into massive performance
issues because the language you chose
was JS the thing you want to fix is
performance so you look for things that
fix performance I would make a
counterargument a lot of the time there
are performance problems it's not
because the language itself is slow it's
because the language doesn't have a good
way to do concurrency and this is where
erlang Elixir beam and all these things
have a massive massive advantage they
are so good at concurrency their code is
still really fast I'm not saying that
Elixir and orlang and these things are
slow they're not they're not as fast as
a language that is memory manually
optimized like rust but they're really
performant more importantly though they
make concurrency trivial to implement so
if you have multiple cores lying around
the ability to just spawn processes on
them and collect them in a map without
writing any meaningful code is so
comically better that I think for a lot
of things these systems are better
replacement for JavaScript than
something like rust if your performance
issue could be solved theoretically by
making JS really good at concurrency you
might not need to go to rust in the
first place and that's why I'm excited
here because there's so many problems
where single-threaded JS even
single-threaded Ruby is obviously not
good enough well you don't need to go to
rust instead we don't even need to go to
goang instead we need to go somewhere
that is not going to make our lives
harder as devs maybe it'll even make
them easier while also giving us
incredible concurrent Primitives that
have logical behaviors and scale
infinitely this is how WhatsApp was
would be built with like what five
Engineers when they were acquired with
hundreds of millions of users that's
only possible because the concurrency
model of earling is so powerful but yes
theoretically on a single-threaded
benchmark this is going to be slower
than rust complain to my comments
anyways gleam has robust static analysis
and a type system inspired by languages
such as Elm old camo and rust so the
compiler serves as a programming
assistant giving you additional context
to help you make the changes you want to
make don't worry about writing perfect
code the first time with gleam
refactoring is low risk and low stress
so you continue to improve your code as
you learn more about the problem at hand
it's cool that refactoring is like part
of their design goals of the language I
think that's somewhat rare I'll say rust
is good about this not good in the sense
that you can meaningfully change the way
a code base Works quickly but it's good
in the sense that if you make a mistake
while making changes you get yelled at a
bunch and it helps you think through
those things whereas typescript kind of
lets you YOLO while also being able to
rename things without it all Breaking
seems like they're aiming for something
between those which is exciting running
administrating software is as important
as writing it gleam runs on the earling
VM a mature and battl tested platform
that powers many of the world's most
reliable and scalable systems such as
WhatsApp I I will admit WhatsApp being
our go-to thing to sight we need more we
really need more there are a lot more
the Telecom world is deep on all things
beam in Arling that's what it was built
for originally but we need better
companies to site here gleam can also
run on JavaScript wait I did not read
that part what what gleam can run and Ja
gleam can run in JavaScript run times
huh okay that changes things so now you
can run gleam code in browser on mobile
or anywhere else here's an example of
some gleam handle request request
context response use Json wisp cool this
is using the Wisp to get Json out of the
request let result use data try to
decode it the Json as a person is a
model that has been imported I'm
assuming yeah my app person so we've
created this model we're trying to
decode the Json as that model then we're
trying to insert the person into
database and we have the row now okay
person. tojson row this is taking that
row and asserting that that's okay then
we have a result case if okay then we
Json respond and if error then we say
it's an unprocessable entity using wisp
which is I'm assuming their web
framework got to love some good pattern
matching this is so nice just case
result and then the cases are two things
that could be the case so okay Json is
only true if the Json result is okay if
it isn't then error empty is the case
instead nice and clear clean good stuff
what does gleam V1 include well this
version covers all the public apis found
in the main gleam git repo which is The
Gleam language compiler build tools
package manager code formatter the
language server and the compiler for
wasm apis and JS bindings that's a lot
to include in a V1 release it's also
really nice seeing the code formatter or
and language server being prioritized
enough to be in this announcement post
especially code formatter huge shout out
to go for normalizing this the idea of
what if the language just had one way
supposed to look so that the developers
can stop bitching about syntax
constantly we just pick it for them and
then it works I love that the this is
now normal for new languages is so cool
I still remember when Elixir added
format and was so so hyped to not have
to worry about those things in my code
base anymore go was first at this I
believe there's some things in R now too
but having this be a thing from the
official team squashes out so much
think about how many videos
I've made and how much time I've wasted
just complaining about ways to format
turn Aries that doesn't happen when you
have a formatter built into the language
really cool stuff they they also have
the language server which is great
because this means not only can you have
a good experience in whatever editor
they chose to support which is obviously
going to be vs code now someone like
Prime can go build the bindings to use
this language server inside of vim and
it takes almost no time to do that if
you implement the language server
protocol correctly which I'm sure they
did if they're advertising it here
really exciting stuff and also the wasm
stuff which we're going to have to play
with at the end of this so stick around
if you want to see me actually trying it
The Gleam standard library and other
packages maintained by the core team
will be getting an accompanying V1
release shortly afterwards before these
are least we will be making poll
requests to Popular Community packages
to relax their package manager version
constraints to ensure that updating to
V1 is as smooth as possible for all
gleam users that's really cool since
they're are 1.0 now it might not be that
different from 0.9 or whatever it was on
before and a lot of community stuff
probably says it requires v.9 which
means sver is going to say hey you can't
install that on 1.0 rather than just
letting that be the community's problem
they're going to go file poll requests
to those major packages to bump them to
1.0 and make sure they're ready for it
so that the packages the community
relies on now won't be as painful to
install really cool to see but what does
V1 even mean for them well version one
is a statement about gleam stability and
Readiness to be used in production
systems We Believe gleam is suitable for
use in products that matter and gleam
will provide a stable and predictable
Foundation gleam follows semantic
versioning so maintaining backwards
compatibility is now a priority we'll be
making every effort to ensure gleam does
not introduce braking changes the
exception to this is for security and
soundness issues should a critical bug
of that nature be discovered we reserve
the right to fix a security issue even
if programs were taking advantage of the
bug I've noticed this is a big thing in
the erlang community they really hate
breaking changes alixir has been
considered a completed Language by the
core team for a while now and most of
the features are fixes to things and
like quick API patches to make other
people's packages more capable within
the ecosystem but they're not adding new
language features to Elixir really ever
anymore one of the main reasons that
they've done that is they built a
language that's so extensible that the
things you'd want to add can largely be
added via libraries plugins and other
packages in that just seems like how the
earling world Works to be fair they're
all running on a VM that's like 30 to 40
years old so it makes sense they want
the old things and the new things to run
well but it is cool to see all these
languages building on top of it
maintaining the spirit of never breaking
your
stuff so what's next for gleam gleam is
a practical language intended for making
real things so our focus with gleam post
V1 is to be split between the
productivity for gleam users and
sustainability for The Gleam project
productivity side they're civically
calling out the breaking changes again
they'll also be avoiding language blow
it's a big thing they call out earlier
they clearly are inspired by like go and
how simple things are they want there to
be one way to do things it's cool that
they want to maintain that it's easy to
keep adding new features to a language
to Aid with specific problems but with
each new language feature or new way of
solving a problem the language as a
whole becomes more complex and harder to
understand Simplicity is a feature in
gleam and that will not change going
forward there is scope adding new
features to the language but we will be
doing so extremely conservatively any
new feature has to be generally useful
and enable new things not otherwise
possible in gleam while being a
worthwhile tradeoff for the added
complexity it brings to the language I
like that they're calling this all out
early like here is how we're thinking of
what to and not to add to our language
rather than adding new features to the
language we'll be continuously improving
The Gleam developer experience and
enhancing real world productivity
initially the focus will be on improving
the language server as it's immature
compared to the rest of the gleam
tooling these really honest call outs
are rare and nice I've never seen a post
like this just straight up saying this
part's not good enough we're going to
fix it we also be working on all of the
libraries and such that folks will
likely want when making production
systems in gleam with an additional
focus on development of websites and web
services makes sense that they're
targeting this it's it's cool that
they're aware of this being the right
initial focus and eventually doing more
like microservices scalable servers all
those types of crazy things
documentation is always a priority we
want to have tutorials and guides for
all manner of tasks in gleam it should
always be easy to find how something is
done in gleam so you can focus on
achieving your goal here's the
sustainability section gleam is not a
project from Microsoft or Google it's a
community project there's one full-time
Dev working on it me I'll get his name
right after as well as a number of
part-time volunteers who do excellent
work with this small team we need to be
efficient with our efforts anything we
work on needs to be impactful and
meaningful to the whole gleam Community
we cannot afford to spend time on Niche
or unimportant situations I want to
quickly call out a couple things first
off I want to get the name of that
author I should just go back to the blog
post to get that at the bottom I also
want to call out fly fly's dope I know
they're not a thing I talk about a lot I
have a couple videos where I cover stuff
they're working on but fly has quickly
become one of the most important
contributors to the erlang and elixir
ecosystems by a lot and they're really
taking the opportunity here to jump on
another thing in the beam world really
cool to see them jumping on this and
helping support a project like this
especially if this project is by poor
Lewis all by himself right now so huge
shout out to fly for jumping on these
things as much as they do and as they
say here anything they work on needs to
be impactful and meaningful to the whole
Community otherwise they can't afford it
because they don't have the time to
spend on Niche or unimportant situations
internal docks are also important so an
open source project we want folks to be
able to open up the code base and make
their contributions as easily as
possible so far the feedback has been
that gleams compiler and build tools are
easy to contribute to that's encouraging
and we'll continue to work on this to
ensure The Gleam project never gets to a
point where only a select few people are
able to meaningfully contribute to its
maintenance uh let's take a quick look
on GitHub first off I need to start this
repo because holy this is really
cool 6.2k Stars I'm expecting this to be
over 10K by the time this video has been
out for 24 hours so hit the link in the
description go give them a star we need
to support cool new projects like this
especially when they're being done
independently what I wanted to see here
is insights that's actually huge
obviously he's been working on this
forever now but seeing multiple new
people coming in with really solid
amounts of contributions especially if I
was to shorten the dates here which I
think is a thing you can do via the URL
if I recall okay I can't trivially do
that there's some way to modify the URL
so it shortens to just be like a Time
window but it looks like recently there
are some people making massive
contributions 139 commits from a third
party that that's working on this
part-time I he's he's a core team member
but it's clearly not his job as well as
Anis contributing a ton crowd haer
having this many people over 100 commits
is nuts for reference here is es build
which is the glue holding together a ton
of the web ecosystem right now and here
you see the next highest number of
commits is 16 and then we have seven
then we have six here we have
significantly more I'm not picking onest
build when I say this I just think it's
important to understand the different
projects in different communities have
different expectations around
contribution and it seems like gleams
made it a high priority to make
contribution meaningfully easy and it's
showing in the numbers already for
something this early that's huge I
haven't looked at the code base I can't
say for sure but I'll back up the
feedback here that it's easy to
contribute to seems like people are
making good contributions okay this is
an important piece last part of
sustainability is financial I'm able to
afford to work on gleam fulltime thanks
to the support of the project sponsors
on GitHub sponsors the largest
contributor is fly who provides
approximately half the funding thank you
fly we wouldn't be here today without
your support going forward I'd like to
diversify the funding with more
corporate sponsors as well as other
revenue streams I earn less than half of
what I would make with the median lead
developer salary in London the city in
which I live this is enough money for me
to get by but I would very much like to
earn around what I would if I had some
other job this is very fair if you're
inventing a new programming language
hopefully you can get the sponsors and
support that you deserve and again to
anybody watching if you have the spare
funds to support this developer and
you're interested in what he's doing
absolutely do that if you work at a
company that might benefit from the work
he's doing bring that up internally it's
always a good thing to have your name in
these types of sponsors and it's
surprisingly cheap to do we go look at
his GI him sponsors I bet a lot of the
numbers are
public he has a goal of 256 monthly
sponsors uh does not have it public oh
well regardless as he said he's making
around half of what a median lead
developer salary would be in London so
let's see what this would be about 75k
so about 100K USD that's what I was
going to guess checks out which means
he's making half which is 50k and fly is
contributing half the funding which is
another half so fly is contributing 25k
a year in order to be this giant logo on
the homepage do you know how cheap that
is do you know how cheap it is to put
your logo on a homepage for an upand
cominging programming language like that
that's insane if you're a company that's
interested in the earling ecosystem
throw this dude some money it's cheap
you get huge positive press and
involvement in an awesome new growing
project and you're financially
supporting it and it's probably going to
go way further than 25 with an a
traditional marketing budget jump in
here it's a huge opportunity and I'm
pumped that F taking it and honestly Le
I hope that this helps like let me know
if in the comments in my DMs however you
want to reach out to me if there's
anything else I can do to help because
projects like this deserve really good
sustainable long-term support even call
this out here long term you'd like to
financially reward the regular
contributors to gleam folks in the court
team are talented and they should be
rewarded appropriately for their work I
totally agree and I really hope we can
get you some more funding because you
deserve it they also have a new mascot
well a glow up mascot Lucy's a kind and
friendly little starfish who enjoys
strawberry ice cream and functional
programming honestly relatable the rest
of Lucy's story is up to the community
to tell thank you to Suppy ly for the
wonderful redesign and for starting
Lucy's Cannon to go with Lucy's New Look
we've also snazzed up the website a
little bit and adjusted the colors for
legibility we hope you like it that's
everything that's really cool
things this is the list of all the
people who have contributed sponsored
and helped good stuff this is so cool
thank you for reading and I hope you
enjoy gleam enough talk we need to play
with this don't tell me they have a
whole how do they have a better learning
point than most like modern web tools
and Frameworks what I want to go through
some of the tutorial here Welcome to The
Gleam language tour I'll be sure to
leave a link to this in the description
if you want to check it out hard to put
into words how cool it is they have this
already for such an early launch like
big web Frameworks don't even have these
tools yet and this new language by one
dude does anything you print using io.
printline or i. debug will be shown at
the bottom section along with any
compile errors and warnings to evaluate
gleam code the tour compiles gleam to
JavaScript and runs it all entirely
within your own browser window cool
here's a program that prints out hello
Joe that's actually really fast for
compiling your different language and
then running that's dope unqualified
Imports normally functions from other
modules are used in a qualified fashion
with the module qualifier being before
function names for example io. printline
it's also possible to specify a list of
functions to import from a module in an
unqualified fashion such as print Line
This is the equivalent in JavaScript of
import thing from stuff you could import
stuff as like that and then do stuff.
thing but their language lets you do
this as part of the import syntax going
left to right I actually really like
this I have a whole video about how we
do Imports wrong in JavaScript because
you can't autocomplete this if you don't
know what module it's part of by putting
the module first by putting the scope
next and then putting the thing you want
third autocomplete can carry you through
that well this okay they don't have the
auto complete in the browser which makes
sense but this has all the pieces they
need to do that experience really well
cool GLE has a robust static type system
as well let's play with the types
uncomment okay the keyboard syntax and
stuff is not quite as good here it's
pretty good overall the language looks
phenomenal though and the highlighting
everything's solid error type mismatch
Source main. gleam IO print line 4
expects a string and it got an INT if I
wrap this in
string now it's good or I could change
it to debug which will take things that
aren't strings nice gleam has no null no
implicit conversions no exceptions and
always performs full type checking the
code compiles you can be reasonably
confident it does not have any
inconsistencies that may cause bugs or
crashes that SS like a certain other
language that is not my favorite thing
in the world it's cool they're doing it
here though gleams int type represents
whole numbers equality double equals
that isn't stupid nice when running in
the earling VM ins have no maximum
minimum size when running in JavaScript
ins are represented using javascript's
64-bit floating Point numbers cool that
they have like this explicitly called
out The Gleam in standard Library module
contains functions for working with ins
well they have a library just for doing
ins and doing them properly in. Max in.
clamps my question would be if I delete
this everything still behaves fine yes
so these are only you only need to
import in here in order to use it for
the int Max in clamp in these standard
Library functions seems like the
standard library is in a good State
though soly another thing I can say
about my favorite language gleams float
type represents numbers that are not
integers cool we know what a float is
number formats oh yes thank you for the
underscore syntax this makes my life so
much easier with random big numbers it's
really nice you even do floats oh that's
really nice gleam has equals and not
equals operators cool strings that there
a classic concatenate option always cool
to see things like this being built in
and working all the Unicode escapes all
built in looks good to me Bulls either
true or false we know how booleans work
assignments I have to test something
important let fire equal testing no I
just wanted one more language that would
let me use emojis for variable
definitions why can't any language let
me use variables that are emojis not
asking for a lot yeah only Swift allows
this right now it's the one thing that I
want more languages to do just give me
Emoji support for my variables and Julia
does apparently according to chat good
to know assignments uh variables could
be reused later but the value they
reference is immutable nice immutable
values we love that discard patterns if
if variable is assigned but not used GLE
will emit a warning variables intended
not to be used the name can be prefix
with an underscore so if I just don't
use that we get a warning with the
prefix we don't get a warning that all
being part of the language compiler is
really nice type annotations let
assignments can be written with a type
annotation after the name type
annotations may be useful for
documentation purposes but they do not
change how gleam type checks the code
Beyond ensuring The annotation is
correct interesting that this is
optional they really leaned into the
inferred everything which I love it's so
cool seeing type inference as like the
core of the language try changing this
um in cool if I change this to not be
underscore name and I tried to change
this to name equals 4 nope I'm curious
if we can do crazy things with the type
definitions Hub type user ID int user ID
int cool also able to resolve deep there
nice
blocks oh oh yes thank you I've had like
three problems in code reviews in the
last two days that made me want this in
JavaScript so badly do you know how
great this is to not have to like make a
function just to call it to keep
variables within a scope what this does
for those who aren't familiar is it lets
us to find a bunch of in here so if
I just was to also do like let Celsius
equals some random IOD do debug
Celsius just so that they're all being
used Celsius isn't touched here even
though I defined it there since it lives
within this closure it effectively
disappears afterwards which means
whatever you do at the end here can now
be assigned here I can have this little
section that goes and does its own
and not have to call a function or in
line a bunch of stuff it just does it
Wonder can I do return they have return
keyword they don't that's annoying I
hate implicit returns I like explicit
can functions return things or is it
literally just whatever you put at the
bottom is whatever you put at the bottom
not my favorite thing fine yeah having
block closures like this is so so so so
useful I am hyped on this yeah and again
the example here is if you uncommon
degrees this won't compile because
degrees is only defined within this
scope it's not defined outside of it so
this won't work because we don't have
access to it because it was put in these
brackets that is so nice the number of
random functions I've defined that just
call themselves that this helps us
Escape magical lists lists are order
cool yeah we know how lists work the
interesting thing here is that lists are
immutable very similar to Elixir I think
it's a thing in earling as well
mutability is great love this lists are
immutably single linked lists the
benefit here is you don't have to worry
about like running a DOT reverse and it
breaking your original list if you want
to make changes to your lists you make a
new list this is how it should be I love
this Nan's the creator of stylex he
loves lurking in chat and I trust his
takes on language design if the only
issue he has with gleam is implicit
returns that sounds like a pretty good
language to me and I'm thus far are
leaning the same way because God this is
really impressive the more I look in the
more happy I get constants cool we know
how constants work but they're actually
constants unlike in certain other
languages who who would ever make those
other languages the FN keyword is used
to define new functions the double and
multiply functions are used are defined
without the pub keyword this makes them
private functions interesting oh just
Pub yeah that is expected Pub is just to
make this exported so other things can
access it I thought that was more
complex than it is that's really simple
and obvious that's the equivalent of
like export nice and simple higher order
functions nice functional programming
languages need the ability to stack
functions and it looks like we can do
that we have add one which takes an INT
and it returns argument plus one that
syntax looks really familiar for type
definitions ravs must be pumped right
now twice argument it also takes in a
function into int and it runs this
function twice that's cool I would have
named this function I'd say past Funk
I'm sure I can no hm in GLE functions
are values they could be assigned to
variables past other function anything
else here function add one is being pass
as an argument FN is not what I should
use there um past function somebody said
is it camel case yeah it's a they can't
you can't camel case past Funk not a
valid name they actually enforce camel
case cool I didn't like this being
called function cuz confusing cool stuff
Anonymous functions again really
important to be able to quickly inline a
function when you need to shouldn't
always have to Define so in this
case we Define add1 equal FNA A+ 1 and
we pass that as a variable here nice
simple to the point cool stuff function
captures g a short hand synex for
creating Anonymous functions to take an
argument and immediately call another
function with that argument trying to
figure out how to explain this this is
an interesting bit Anonymous function
can be written as with any number of
arguments passed to the inner function
the underscores a placeholder for the
argument okay so add 1 V2 okay now I
think I know how to explain this so if
you want to quickly Define a function
that is just calling another function if
you put underscores for the arguments
those become the arguments for your
function so if I change this to be a b i
no uh random string this variable is
never used but if I IO do print Ln
random now we're getting an issue that
we didn't pass the argument here so I'll
pass hello here now we're getting the
same thing here the interesting thing
with the underscores is now for add 1 V2
I've basically told the compiler add 1
V2 takes two arguments and they're these
two in this order so since I put these
blanks here it will just expose those in
the OD one function so now I can do hi
there's more than one argument hole in
this function call um I assume you can
do multiple oh it's just for one
argument okay it makes sense that it's
just for one argument limits what you
can do with this but it convenient to do
something like that where a function
needs some things pass but you want to
expose just one thing to be quickly
called inline it's a quick way to do
that be cool if you do more with it but
it's a nice quick syntax there's also
generic functions you know the thing
that go finally added generics in
general anyways up until now each
function has accepted precisely one type
for each of its arguments the twice
function for example only works with
functions that would take and return ins
cool so twice takes in a function with
value value value this is a generic
though so theoretically you can Define
whatever you want this to take we have
an add one here where function of X is
returning X+ one and exclaim which is
function of x x exclamation point so
these both are this would infer to a
number and this would infer to a string
for the inputs here the type variable is
replaced by the type int so we're
calling twice with the number 10 and add
one it knows that's a number the type
definition gets handled I change this to
xclaim we'll get an error because xclaim
been inferred to need a string instead
of a number and since we gave it a
number in a string twice is smart enough
to infer that these things are different
that the value and the type definition
here is different from the type
definition for the function return and
since these are different it gets mad at
you this is really cool reverse
inference it's nice to see this in a
language that isn't rust or o camel and
my favorite my absolute favorite the
thing I cannot believe has not made its
way to JS yet pipes it's so good it's so
simple there are so many times where you
like let's be real who who has written
this code before let's say we have const
user equals some stuff now we need to do
something with the user const off user
equals off user then you have your
function that actually does something to
it like you format it or you process the
payment so const processed user equals
process off user and then return like
process request processed user there's
only three possibilities for everyone
here either you don't write JS you write
JS and you've done this a bunch or
you're lying because this is one of the
most common things I find myself doing
where I'm defining like 15 variables
just to use them once as I pass them to
the next thing the other option I could
have here is I could take this put it
here take this put it here take this put
it here and no one likes this especially
once the chains get big this is the
worst What If instead of compromising on
both the line syntax as well as from
having to define a bunch of variables
you shouldn't have to name every single
step along the way one what if a pipe
just took the thing from the last line
and made it the first argument in the
next line so here we take one we append
two to the end and then after here's
where it gets interesting because we
have the blank here we're passing one to
that spot instead if we don't have that
it just goes in the front we get 1 2
three but if we put that blank we also
put it here and that's going to be 2 one
three because one gets put after two
when you put the blank there three blank
same deal 312 tell me that's not the
coolest in the world tell me that's
not hilariously cool going to try one
thing I'm actually not sure this will
work but I'm so so curious uh hello oh
since this isn't a whole argument it's
not smart enough to pass it through was
worth a shot still so cool I love this
so much labeled arguments more really
handy useful features when functions
take several arguments it can be
difficult to remember what the arguments
are and what order they're expected in
to help with this gleam supports labeled
arguments where function arguments are
given an external label in addition to
their internal name so this is what it's
called externally multiply internally
it's going to be called multiplier
externally is be called internally it's
going to be add end cool not super super
important but nice documentation
comments documentation comments are
important they have regular double slash
as well as triple and quadruple slash
which are used for attaching
documentation to code triple slash is
for documentation for types and
functions quadruple slash is for modules
and should be placed at the top of the
module so here's the definition for the
module here's everything else I would
like something different than additional
slashes it's a little too easy to like
glance over and not notice the
difference there but the fact they have
Syntax for this built into the language
version one is really nice deprecations
cool everything should have that case
exceptions they have a whole pattern
matching section in here
maybe a bunch of flow control
stuff I could sit here all day just
going through the different language
decisions I don't want that to be what
this video becomes but I do want to take
a look at cases and pattern matching so
here's a pretty simple case we have X
which is a random int 01 or other you
pass it it's X let results it's zero we
print zero if it's one we print one
otherwise we print other I refresh
this get different values each time cool
last the program to say if this data has
this shape then run this code a process
called pattern matching I'm going to do
something silly I'm just curious if this
works 1 2 3 here we can pattern match to
say one two we don't care one 2 4 and
then here we don't care either int is
never used cool first case second case
this will be a good example so we'll do
1 2 3 and then 1 2
4 then 1 2 underscore so we're going to
hit the first case here cu the array is
1 2 3 and it matches 1 2 3 where things
get magical though is you can opt out of
certain arguments there's now
unreachable cases which makes sense that
it's actually really cool that compiler
smart enough to notice that so I'll
actually delete these other cases
because the point of this one is very
simple if two is in the middle doesn't
matter what the other values are this is
what we should run this is so so nice
the alternative here would be in like a
case true and each of these values would
be doing a manually written if check in
something like typescript but here it's
just built into the language in the case
syntax when you pass something like an
object or an array the level of
specificity in your match is up to you
that is so good you could also somebody
just said Define a variable here so if I
wanted to do first case Fu can I cast
this is a string let me import gleam int
int. 2 string I'm
assuming look at that look at how
helpful they little compiler stuff is so
now since we bound Fu as the third
argument here we can actually pass it
but we could also make a case here
that's like one 3 4 we don't have that
variable so I'll just delete that for
now and the magic here is whichever case
your code passes first is the one that
you hit I change this to 133 it will
only match the bottom so we get other
change this to 134 it matches this
middle case if I change this to two in
the middle again even if I have two here
it'll hit this first case because it
matches and it's going through step by
step so it says okay here's the first
one we don't care about the first
argument two two cool that matches four
F cool we can B that everything matches
cool run the code wait no it doesn't
check the next one this is I don't know
how to put into words how much this
helps with maintainability it looks good
here once you get into function
overloads where you're defining the same
function four times and defining these
things in the syntax for the function
definition that's where it gets crazy
that's curious if they have function
overloading that's the one thing I would
really like oh that's the one thing I
really want
they actually have oh wow they have a
whole guide for gleam for Elixir users
they're really focused on this stuff
that's dope unlike Elixir gleam does not
support function overloading there can
only be one function with a given name
and the function can only have a single
implementation for the types it accepts
I get it I'm sad but I get it there had
to be some negative right couldn't be
literally perfect language it's close
it's weirdly close but it couldn't be
perfect I think I've covered everything
I want to here it's clear there's way
more I didn't even start going into
luster which is their web framework it's
not actually by the core gleam team but
it is a supported functioning web system
for writing gleam in the browser which
is really really cool they're already at
that point I haven't been this excited
about a new language in a minute I'll be
honest I am blown away if you haven't
already checked out gleam go take a look
and if you can support the team making
it because they're clearly working
really really hard that's all I to say
for now until next time peace nerds
5.0 / 5 (0 votes)