2018-08-30 20:30:49 +03:00
|
|
|
--map/traverse
|
2021-08-24 21:33:27 +03:00
|
|
|
structural ability Noop where
|
2018-08-30 20:30:49 +03:00
|
|
|
noop : a -> {Noop} a
|
|
|
|
|
2021-08-24 21:33:27 +03:00
|
|
|
structural type List a = Nil | Cons a (List a)
|
2018-08-30 20:30:49 +03:00
|
|
|
|
|
|
|
map : (a ->{} b) -> List a -> List b
|
2020-02-22 02:48:12 +03:00
|
|
|
map f = cases
|
2018-08-30 20:30:49 +03:00
|
|
|
List.Nil -> List.Nil
|
|
|
|
List.Cons h t -> List.Cons (f h) (map f t)
|
|
|
|
|
|
|
|
c = List.Cons
|
|
|
|
|
|
|
|
z : ∀ a . List a
|
|
|
|
z = List.Nil
|
|
|
|
|
|
|
|
ex = c 1 (c 2 (c 3 z))
|
|
|
|
|
2019-02-21 22:49:12 +03:00
|
|
|
pureMap : List Text
|
|
|
|
pureMap = map (a -> "hello") ex
|
2018-08-30 20:30:49 +03:00
|
|
|
|
|
|
|
-- this should not typecheck because map is annotated to take a pure function
|
2018-09-24 20:15:40 +03:00
|
|
|
zappy : '{Noop} (List Nat)
|
|
|
|
zappy = 'let map (zap -> Noop.noop (zap Nat.+ 1)) ex
|
2018-08-30 20:30:49 +03:00
|
|
|
|
2019-02-21 22:49:12 +03:00
|
|
|
pureMap
|