Skip to content

Instantly share code, notes, and snippets.

@srid
Created November 17, 2016 15: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 srid/c3684c15fb4b2a15fabf31623f2018d5 to your computer and use it in GitHub Desktop.
Save srid/c3684c15fb4b2a15fabf31623f2018d5 to your computer and use it in GitHub Desktop.
Attempting fixed list in Elm
module FixedList exposing (..)
type Nil a = Nil
type Cons fa a = Cons a fa
type alias FixedList0 a = Nil a
type alias FixedList1 a = Cons (FixedList0 a) a
type alias FixedList2 a = Cons (FixedList1 a) a
fl1 : FixedList1 Int
fl1 = Cons 1 Nil
fl2 : FixedList2 Int
fl2 = Cons 2 fl1
fl2_1 : FixedList2 Int
fl2_1 = Cons 2 (Cons 1 Nil )
map : (a -> b) -> Cons fa a -> Cons fa b
map f (Cons x xs) =
Cons (f x) xs
map0 : (a -> b) -> FixedList0 a -> FixedList0 b
map0 f Nil = Nil
map1 : (a -> b) -> FixedList1 a -> FixedList1 b
map1 f (Cons x xs) =
Cons (f x) (map0 f xs)
map2 : (a -> b) -> FixedList2 a -> FixedList2 b
map2 f (Cons x xs) =
Cons (f x) (map1 f xs)
fl2_mapped = map2 ((+) 2) fl2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment