Skip to content

Instantly share code, notes, and snippets.

@timjb
Created September 26, 2014 16:51
Show Gist options
  • Save timjb/516f04808f0c4aa90c26 to your computer and use it in GitHub Desktop.
Save timjb/516f04808f0c4aa90c26 to your computer and use it in GitHub Desktop.
{-# LANGUAGE TypeFamilies, DataKinds, TypeOperators #-}
module HListCurry
( HListElim
, hListCurry
, example
) where
import Data.HList
type family HListElim (ts :: [*]) (a :: *) :: *
type instance HListElim '[] a = a
type instance HListElim (t ': ts) a = t -> HListElim ts a
hListCurry :: HListElim ts a -> HList ts -> a
hListCurry f HNil = f
hListCurry f (HCons x xs) = hListCurry (f x) xs
example :: String
example = hListCurry (\i s -> show i ++ s) (HCons (3 :: Int) (HCons "hallo" HNil))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment