Created
January 27, 2015 15:22
-
-
Save kanterov/70450c5f9c389e11d31c to your computer and use it in GitHub Desktop.
HList experiment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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