From 4d28321457e22e89ba840402738a53e7cc32e7f5 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Mon, 24 Feb 2020 11:27:18 +0100 Subject: [PATCH] rank2 --- rank2/test.icl | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 rank2/test.icl 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 -- 2.20.1