Skip to content

Instantly share code, notes, and snippets.

@Gozala
Created September 1, 2017 17:08
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 Gozala/84c779974362889ab6e192279f4c6711 to your computer and use it in GitHub Desktop.
Save Gozala/84c779974362889ab6e192279f4c6711 to your computer and use it in GitHub Desktop.
HList in Elm
module HList exposing (HList, cons, nil first rest)
type HList x xs
= Nil
| Cons x xs
nil = Nil
cons : x1 -> HList x2 xs -> HList x1 (HList x2 xs)
cons head tail =
Cons head tail
first : HList head tail -> Maybe head
first hlist =
case hlist of
Nil ->
Nothing
Cons head tail ->
Just head
rest : HList head tail -> Maybe tail
rest hlist =
case hlist of
Nil ->
Nothing
Cons head tail ->
Just tail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment