-
-
Save k-bx/32b3f6a770ad81330f51 to your computer and use it in GitHub Desktop.
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
/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 () |
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 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