rank2 polymorphism problem with newtypes
Using this file (both with the itask and the master compiler):
module test
import StdEnv
import Data.Maybe
import Data.Functor
import Control.Applicative
class expr v where
lit :: i -> v i | toString i
(+.) infixl 6 :: (v i) (v i) -> v i | + i
instance expr Maybe where
lit i = Just i
+. x y = (+) <$> x <*> y
:: Print a = Print String
print :: (Print a) -> String
print (Print a) = a
instance expr Print where
lit i = Print (toString i)
+. (Print l) (Print r) = Print (l +++ "+" +++ r)
printEval :: (A.v: v a | expr v) -> (Maybe a, String)
printEval f = (f, let (Print p) = f in p)
Start :: (Maybe Int, String)
Start = printEval (lit 4 +. lit 38)
This works fine and gives the output:
((Just 42),"4+38")
However, if we change
:: Print a = Print a
to
:: Print a =: Print a
The output is wrong, and when we use the second element it obviously crashes:
((Just 42),_f54;54.12)
If we change
printEval f = (f, let (Print p) = f in p)
to
printEval f = (f, print f)
It works again.
The construction let (Print p) = f in p
works fine in a non rank2 polymorphic function