Last active
July 1, 2019 08:44
-
-
Save alexpeits/953f44ab1f797131ba5f98f46359093b to your computer and use it in GitHub Desktop.
Function arguments to HList (i-am-tom's work)
This file contains 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
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE FunctionalDependencies #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE KindSignatures #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
module ArgsToHList where | |
import Prelude hiding (uncurry) | |
import Data.Kind (Type) | |
data HList (xs :: [Type]) where | |
HNil :: HList '[] | |
HCons :: x -> HList xs -> HList (x ': xs) | |
class HUncurry (before :: Type) (after :: Type) (inputs :: [Type]) | |
| before after -> inputs where | |
hUncurry :: before -> (HList inputs -> after) | |
instance {-# incoherent #-} (a ~ b, c ~ '[]) => HUncurry a b c where | |
hUncurry = const | |
instance ( HUncurry a b c | |
, d ~ ( x ': c ) | |
) => HUncurry (x -> a) b d where | |
hUncurry before (HCons x xs) = hUncurry (before x) xs | |
f :: Int -> Bool -> Char -> String | |
f i b c = show i <> show b <> show c | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment