Skip to content

Instantly share code, notes, and snippets.

@ethagnawl
Created August 5, 2017 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethagnawl/596f75697e12727af0755149329951b7 to your computer and use it in GitHub Desktop.
Save ethagnawl/596f75697e12727af0755149329951b7 to your computer and use it in GitHub Desktop.
elm extensible records example
module Main exposing (..)
import Html exposing (Html, text)
type alias Named a = { a | name : String }
foo : Compound -> String
foo named = named.name ++ "!"
type alias Position r = { r | x:Float }
type alias Velocity r = { r | vx:Float }
type alias Person r = { r | name:String }
type alias Compound = Person (Position (Velocity {}))
main : Html a
main =
let compound = {x = 1.0, vx = 1.1, name = "pete"}
in
text ("hi, " ++ foo compound)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment