Skip to content

Instantly share code, notes, and snippets.

@k-bx

k-bx/err.out Secret

Created February 25, 2015 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k-bx/32b3f6a770ad81330f51 to your computer and use it in GitHub Desktop.
Save k-bx/32b3f6a770ad81330f51 to your computer and use it in GitHub Desktop.
/Users/kb/workspace/typelabels/typelabels.hs
The first argument of ‘Main.TypedLabel1’ should have kind ‘*’,
but ‘Main.Onion’ has kind ‘Main.VegType’
In the type signature for ‘Main.embraceOnion3’:
Main.embraceOnion3 :: Main.TypedLabel1 Main.Onion Main.Vegetable
-> GHC.Types.IO ()
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
module Main where
main :: IO ()
main = putStrLn "Hi!"
data Vegetable = Vegetable { vegName :: String
, vetType :: VegType }
deriving (Show, Eq)
data VegType = Potato
| Tomato
| Cucumber
| Onion
deriving (Show, Eq)
newtype TypedVegetable (t::VegType) = TypedVegetable Vegetable
unType :: TypedVegetable (t::VegType) -> Vegetable
unType (TypedVegetable v) = v
-- | bad
embraceOnion :: Vegetable -> IO ()
embraceOnion veg = putStrLn ("Yay for onion! It's name is: " ++ vegName veg)
-- | good, but little ugly because of boilerplate
embraceOnion2 :: TypedVegetable Onion -> IO ()
embraceOnion2 onion = putStrLn ("Yay for onion! It's name is: " ++ vegName (unType onion))
-- | doesn't work, need to specify kind of `t`
newtype TypedLabel1 t a = TypedLabel1 a
unTyped1 :: TypedLabel1 t a -> a
unTyped1 (TypedLabel1 a) = a
embraceOnion3 :: TypedLabel1 Onion Vegetable -> IO ()
embraceOnion3 = undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment