From: Mart Lubbers Date: Mon, 24 Feb 2020 10:27:18 +0000 (+0100) Subject: rank2 X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=4d28321457e22e89ba840402738a53e7cc32e7f5;p=clean-tests.git rank2 --- diff --git a/rank2/test.icl b/rank2/test.icl new file mode 100644 index 0000000..81685e2 --- /dev/null +++ b/rank2/test.icl @@ -0,0 +1,36 @@ +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 + (v a) | expr v & + a where + + l r = l +. r + +eval :: (Maybe a) -> Maybe a +eval x = x +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 = (eval f, let (Print p) = f in p) + +//Mag niet +Start :: (Maybe Int, String) +Start = printEval (lit 4 +. lit 38) + +//Mag wel +//Start = let (Print f) = lit 4 + lit 38 in f