Skip to content

Instantly share code, notes, and snippets.

@myuon
Created October 18, 2015 05:38
Show Gist options
  • Save myuon/e2b977c452a21d8f3fe0 to your computer and use it in GitHub Desktop.
Save myuon/e2b977c452a21d8f3fe0 to your computer and use it in GitHub Desktop.
{-# LANGUAGE TypeFamilies, DataKinds, TypeOperators, FlexibleInstances #-}
import GHC.TypeLits
type family FuncType (as :: [*]) where
FuncType '[] = IO ()
FuncType (a ': as) = a -> FuncType as
data Name (s :: Symbol) = Name
data FullOption = FullOption {
opt1 :: Int,
opt2 :: String,
opt3 :: [Int]
} deriving (Eq, Show)
class Hoge (s :: Symbol) where
type Arg :: [*]
hoge :: Name s -> FuncType Arg
hogeFullOption :: Name s -> FullOption -> IO ()
hogeFullOption _ opt = print opt
instance Hoge "this" where
type Arg = [Int, Char]
hoge _ n c = putStrLn $ "int: " ++ show n ++ " char: " ++ show c
this = hoge (Name :: Name "this")
main = do
this 10 '#'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment