Commit ea3c659e authored by Joachim Breitner's avatar Joachim Breitner
Browse files

Test coercing under under-saturated newtypes

parent a37c6ad6
......@@ -15,26 +15,34 @@ data Map a b = Map a b deriving Show
newtype List a = List [a] deriving Show
data T f = T (f Int)
-- It should be possible to coerce _under_ undersaturated newtypes
newtype NonEtad a b = NonEtad (Either b a) deriving Show
main = do
print (coerce $ one :: Age)
print (coerce $ Age 1 :: Int)
print (coerce $ Baz (Bar (Age 1)) :: Foo)
print (coerce $ age :: Int)
print (coerce $ Baz (Bar age) :: Foo)
print (coerce (id::Bar->Bar) (Age 1) :: Foo)
print (coerce Baz (Age 1) :: Foo)
print (coerce $ (Age 1, Foo (Age 1)) :: (Baz, Baz))
print (coerce (id::Bar->Bar) age :: Foo)
print (coerce Baz age :: Foo)
print (coerce $ (Age 1, Foo age) :: (Baz, Baz))
print (coerce $ Map one one :: Map Int Age)
print (coerce $ Just one :: First Int)
print (coerce $ (mempty :: Last Age) :: Last Int)
printT (coerce $ (T (Left (Age 1)) :: T (Either Age)) :: T (Either Int))
printT (coerce $ (T (Left age) :: T (Either Age)) :: T (Either Int))
printT (coerce $ (T (Left one) :: T (Either Int)) :: T (Either Age))
printT (coerce $ (T [one] :: T []) :: T List)
printT (coerce $ (T (List [one]) :: T List) :: T [])
printT (coerce $ (T (NonEtad (Right age)) :: T (NonEtad Age)) :: T (NonEtad Int))
where one = 1 :: Int
age = Age one
printT (T x) = print x
......
......@@ -11,3 +11,4 @@ Left 1
Left (Age 1)
List [1]
[1]
NonEtad (Right 1)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment