Main / Program in elm/core

I’m fiddling around with language fundamentals and observed some weird behaviour.
Warning: Deep Dive into the elm/core and elm/compiler ahead.

Context: I’m trying to reverse engineer the Details of main and its “magic Relationship” to Program. I am fully aware that Platform exposes worker, which basically does whatever you want. Nevertheless I stumbled upon funny behaviour which I’m not fully able to explain.

The recipe:

  • Virgin elm project with
{
    "type": "package",
    "name": "elm/core",
    ...
    "dependencies": {
    },
    "test-dependencies": {
    }
}

Add src/Main.elm:

module Main exposing (..)

import Platform exposing (donothing)

main = donothing

Add src/Platform.elm:

module Platform exposing (donothing)

type Program flags model msg = Program

donothing : Program () () ()
donothing = Elm.Kernel.Platform.donothing

What I would expect: Some message about Elm.Kernel.Platform not being in scope.
What I got:

-- ERROR -----------------------------------------------------------------------

I ran into something that bypassed the normal error reporting process! I
extracted whatever information I could from the internal error:

>   Map.!: given key is not an element in the map
>   CallStack (from HasCallStack):
Success! Compiled 2 modules.
91m>     error, called at libraries/containers/Data/Map/Internal.hs:610:17 in containers-0.5.11.0:Data.Map.Internal

These errors are usually pretty confusing, so start by asking around on one of
forums listed at https://elm-lang.org/community to see if anyone can get you
unstuck quickly.

-- REQUEST ---------------------------------------------------------------------

If you are feeling up to it, please try to get your code down to the smallest
version that still triggers this message. Ideally in a single Main.elm and
elm.json file.

From there open a NEW issue at https://github.com/elm/compiler/issues with your
reduced example pasted in directly. (Not a link to a repo or gist!) Do not worry
about if someone else saw something similar. More examples is better!

This kind of error is usually tied up in larger architectural choices that are
hard to change, so even when we have a couple good examples, it can take some
time to resolve in a solid way.elm: Map.!: given key is not an element in the map
CallStack (from HasCallStack):
  error, called at libraries/containers/Data/Map/Internal.hs:610:17 in containers-0.5.11.0:Data.Map.Internal

This message doesn’t change, no matter what I try:

  • Implement stub and expose donothing in Elm.Kernel.Platform (with or without a Platform.js in the Folder)
  • Cloning the real elm/core and add these lines (and doing the previous step)

What have I stumbled upon? I mean even the File which is causing trouble is wonderfully absent but should be here.

It seems like something is hard-coded here. Even the name elm/core. When you change it to whatever, the error message changes, too:

-- MISSING DEPENDENCY ------------------------------------------------- elm.json

I need to see an "elm/core" dependency your elm.json file. The default imports
of `List` and `Maybe` do not work without it.

If you modified your elm.json by hand, try to change it back! And if you are
having trouble getting back to a working elm.json, it may be easier to find a
working package and start fresh with their elm.json file.

Elm is really trying to prohibit any funny ideas. But now, I’m pretty curious. What keys are present in the magic Dict? Can I get somehow deeper? Can anyone explain this weird behaviour?

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.