A series of exercises to get a feel for how generic types and type variables work in Elm.
For each of these, you are given some code that is not compiling. Your task is to get it
compiling. You can change the body of the function but not the signature. No cheating
with Debug.todo
or infinite recursions either 😉
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ID exposing (ID(..), decodeFromString, decoder, encode, encodeAsString, fromInt, toInt, toString) | |
import Json.Decode as Decode exposing (Decoder) | |
import Json.Encode as Encode exposing (Value) | |
{-| This type ensures you get a type error if you for example accidentally pass a UserId in place of a CompanyId | |
-} | |
type ID phantom | |
= ID Int |
If you’ve ever wanted to analyze your own health data, here’s how.
- Open the Health app.
- Tap on your profile in the top right.
- Tap Export All Health Data.
- Share the archive with yourself (e.g. via AirDrop, Files, Mail, etc.).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module NoMissingTypeConstructor exposing (rule) | |
import Dict exposing (Dict) | |
import Elm.Syntax.Declaration as Declaration exposing (Declaration) | |
import Elm.Syntax.Expression as Expression exposing (Expression) | |
import Elm.Syntax.ModuleName exposing (ModuleName) | |
import Elm.Syntax.Node as Node exposing (Node) | |
import Elm.Syntax.Type exposing (Type) | |
import Elm.Syntax.TypeAnnotation as TypeAnnotation exposing (TypeAnnotation) | |
import Review.ModuleNameLookupTable as ModuleNameLookupTable exposing (ModuleNameLookupTable) |
The question of code-splitting in Elm comes up fairly routinely.
The apparent low-hanging-fruit of code-splitting with Elm's pure/immutable philosophy has led me to explore this a few times with my compiler work on Lamdera.
Here are some of the challenges I've found:
It's a little trickier than it looks because Elm's DCE is actually not DCE (dead code elimination) at all, it's LCI (live code inclusion).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- A sketch for a potential responsive API for elm-ui | |
First, the API. Following will be some example code! | |
-} | |
-- defining a set of global window-width breakpoints | |
breakpoints : label -> List (Breakpoint label) -> Breakpoints label |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.customElements.define("elm-portal", class extends HTMLElement { | |
// Base custom element stuff | |
constructor() { | |
super(); | |
this._targetNode = document.createElement('div'); | |
} | |
connectedCallback() { | |
document.querySelector(this.getAttribute("data-target-selector")).appendChild(this._targetNode); | |
} |
A summary of the Elm architectures/compilation/installation/usage matrix state of affairs.
OlderNewer