Skip to content

Instantly share code, notes, and snippets.

@hanshoglund
Last active October 6, 2017 22:12
Show Gist options
  • Save hanshoglund/1d90f284a582022614c7f1cbf2f00bef to your computer and use it in GitHub Desktop.
Save hanshoglund/1d90f284a582022614c7f1cbf2f00bef to your computer and use it in GitHub Desktop.
-- Row-type records as variants and variants as records
-- type Either a b = (left :: a | right :: b)
type Either a b =
forall r . { left :: a -> r, right :: b -> r} -> r
-- type Pair a b = forall r . (fst :: a->r | snd :: b->r) -> r
type PairHelper a b =
forall r . { fst :: a -> r, snd :: b -> r } -> r
type Pair a b =
forall r . PairHelper (a -> r) (b -> r) -> r
eitherEx :: Either Int Boolean
eitherEx k = k.left 1
eitherEx2 :: Int
eitherEx2 = eitherEx { left: id, right: \x -> if x then 0 else 1 }
pairEx :: Pair String Int
pairEx k = k { fst: \j -> j "foo", snd: \j -> j 23 }
pairEx1 :: String
pairEx1 = pairEx (\x -> x.fst id)
pairEx2 :: Int
pairEx2 = pairEx (\x -> x.snd id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment