loading...

Elm's compiler hints

dwayne profile image Dwayne Crooks ใƒป2 min read

When you run elm init it gives you a link that you can go to and read all about elm init to your heart's desire. ๐Ÿ˜

Previously, it used to be a web page. A seemingly lonely web page not linked to anything. I'd usually wonder, "Where could I get more information like this?" ๐Ÿค”

Occasionally, I'd do something heretical in Elm like variable shadowing and I'd be pointed to another one of those lonely web pages to get a lengthy talk from father Evan. ๐Ÿ˜ฌ And again I'd wonder "How can I do more bad things like that and get more information like this?" ๐Ÿ˜ˆ

Then yesterday happened.

I was reading An Introduction to Functional Programming Through Lambda Calculus and I decided to try to write the self-application function in Elm and boom:

---- Elm 0.19.0 ----------------------------------------------------------------
Read <https://elm-lang.org/0.19.0/repl> to learn more: exit, help, imports, etc.
--------------------------------------------------------------------------------
> selfApply = \s -> s s
-- INFINITE TYPE ----------------------------------------------------------- elm

I am inferring a weird self-referential type for s:

3| selfApply = \s -> s s
                ^
Here is my best effort at writing down the type. You will see โˆž for parts of the
type that repeat something already printed out infinitely.

    โˆž -> a

Staring at this type is usually not so helpful, so I recommend reading the hints
at <https://elm-lang.org/0.19.0/infinite-type> to get unstuck!

When I navigated to the link, https://elm-lang.org/0.19.0/infinite-type, this time it redirected to a Markdown file. After reading it I went one directory up.

I had discovered the hidden jewels. ๐Ÿ˜ญ

Yes

See for yourself, hints.

Disclaimer: I know that Evan's intention is that you'd discover these hints as needed when you actually get into problems and at the point you're ready to digest the information. So please keep in mind that you don't need to read this stuff all at once to be productive in Elm.

Mentioned in this post:

Posted on Aug 7 '19 by:

dwayne profile

Dwayne Crooks

@dwayne

A full stack web developer who has an interest in programming language theory, interpreters, compilers and type theory. I enjoy programming with Elm and Haskell in my free time.

Discussion

markdown guide
 

Thanks for sharing this! I really enjoy reading the articles that you write. Elm is intimidating when you first approach it because it appears that there is lots of documentation missing, but I am realizing that you're supposed to go straight to the source code to really understand Elm. Your articles were definitely a major factor in helping me reach that conclusion!

 

... you're supposed to go straight to the source code to really understand Elm

Yes, that's one good way to get better at any programming language. To read well written code.

 

I loled at

...lengthy talk from father Evan.