Skip to content

Instantly share code, notes, and snippets.

@kanterov
Created January 27, 2015 15:22
Show Gist options
  • Save kanterov/70450c5f9c389e11d31c to your computer and use it in GitHub Desktop.
Save kanterov/70450c5f9c389e11d31c to your computer and use it in GitHub Desktop.
HList experiment
module Data.HList
( (.:.)
, head
, tail
) where
newtype HList a = HList a
infixr 5 .:.
(.:.) :: forall h t. h -> HList { | t } -> HList { head :: h, tail :: HList { | t } }
(.:.) h t = HList { head: h, tail: t }
head :: forall h t. HList { head :: h, tail :: HList { | t } } -> h
head (HList r) = r.head
tail :: forall h t. HList { head :: h, tail :: HList { | t } } -> HList { | t }
tail (HList r) = r.tail
type HNil = HList {}
foreign import hnil "var hnil = null;" :: HNil
instance showHList :: Show (HList h) where
show a = unsafeShowHList a
foreign import unsafeShowHList
"""
function unsafeShowHList(hlist) {
var i = "";
while (hlist) {
i = i + JSON.stringify(hlist.head) + " .:. ";
hlist = hlist.tail;
}
return i + "hnil";
}
""" :: forall a. HList a -> String
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment