--- /dev/null
+definition module T
+
+:: T = ..
--- /dev/null
+implementation module T
+
+
--- /dev/null
+module test
+
+import StdGeneric
+import T
+
+
+:: T | T1
+
+generic gDefault a :: a
+
+gDefault{|T|} = T1
+
+Start :: T
+Start = T1
--- /dev/null
+definition module class
+
+class lit m :: Int -> m
+class var m :: String -> m
+class (+.) infixl 6 m :: m m -> m
+
+:: Eval
+instance lit Eval
+instance var Eval
+instance +. Eval
+
+:: Print
+instance lit Print
+instance var Print
+instance +. Print
--- /dev/null
+implementation module class
+
+import StdEnv
+import Data.Func
+import Data.Functor
+import Data.Either
+import Data.List
+import Data.Maybe
+import Control.Applicative
+import Control.Monad
+
+//Easy to add functionality
+//Easy to add backends
+//Type safety as in GADTs
+
+class lit m :: Int -> m
+class var m :: String -> m
+class (+.) infixl 6 m :: m m -> m
+
+:: Eval :== ([(String, Int)] -> Either String Int)
+instance lit Eval where lit i = pure (pure i)
+instance var Eval where var s = maybe (Left $ "Undefined variable " +++ s) Right o lookup s
+instance +. Eval where (+.) a b = \s->liftM2 (+) (a s) (b s)
+
+:: Print :== String
+instance lit Print where lit i = toString i
+instance var Print where var s = s
+instance +. Print where (+.) a b = a +++ " + " +++ b
+
+Start :: Eval
+Start = (lit 5 +. lit 37)
--- /dev/null
+module deep
+
+import StdEnv
+import Data.Func
+import Data.Functor
+import Data.Either
+import Data.List
+import Data.Maybe
+import Control.Applicative
+import Control.Monad
+
+:: Expr
+ = Lit Int
+ | Var String
+ | (+.) infixl 6 Expr Expr
+
+eval :: Expr -> ([(String, Int)] -> Either String Int)
+eval (Lit i) = const $ pure i
+eval (Var s) = maybe (Left $ "Undefined variable " +++ s) Right o lookup s
+eval (a +. b) = \s->liftM2 (+) (eval a s) (eval b s)
+
+print :: Expr -> String
+print (Lit i) = toString i
+print (Var s) = s
+print (a +. b) = print a +++ " + " +++ print b
+
+Start = eval (Lit 5 +. Lit 37) []
--- /dev/null
+definition module exist
+
+from Data.Either import :: Either
+
+:: Expr
+ = Lit Int
+ | Var String
+ | (+.) infixl 6 Expr Expr
+ | E.e: Ext e & eval e & print e
+
+class eval m :: m -> ([(String, Int)] -> Either String Int)
+class print m :: m -> String
+
+instance eval Expr
+instance print Expr
--- /dev/null
+implementation module exist
+
+import StdEnv
+import Data.Func
+import Data.Functor
+import Data.Either
+import Data.List
+import Data.Maybe
+import Control.Applicative
+import Control.Monad
+
+class eval m :: m -> ([(String, Int)] -> Either String Int)
+class print m :: m -> String
+
+instance eval Expr
+where
+ eval (Lit i) = const $ pure i
+ eval (Var s) = maybe (Left $ "Undefined variable " +++ s) Right o lookup s
+ eval (a +. b) = \s->liftM2 (+) (eval a s) (eval b s)
+ eval (Ext e) = eval e
+
+instance print Expr
+where
+ print (Lit i) = toString i
+ print (Var s) = s
+ print (a +. b) = print a +++ " + " +++ print b
+ print (Ext e) = print e
+
+Start = eval (Lit 5 +. Lit 37) []
--- /dev/null
+definition module whileFor
+
+import while
+
+:: WFor = WFor String Is WhileInt To WhileInt Do WhileExpr
+
+(*.) infixl 7
+(*.) a b :== WInt (WMult a b)
+
+instance evali WMult
--- /dev/null
+definition module Mult
+
+from exist import :: Expr
+
+:: ExprMult = (*.) infixl 7 Expr Expr
+
+instance eval ExprMult
+instance print ExprMult
--- /dev/null
+implementation module existMult
+
+import Expr
+
+:: ExprMult = (*.) infixl 7 Expr Expr
+
+instance eval ExprMult
+instance print ExprMult
--- /dev/null
+definition module while
+
+:: Then = Then
+:: Else = Else
+:: Do = Do
+:: WhileExpr
+ = (=.) infix 1 String WhileInt
+ | If WhileBool Then WhileExpr Else WhileExpr
+ | (:.) infixr 0 WhileExpr WhileExpr
+ | While WhileBool Do WhileExpr
+ | Skip
+ | E.e: WExpr e & eval e
+
+:: WhileBool
+ = Bool Bool
+ | (==.) infix 4 WhileInt WhileInt
+ | (&.) infix 3 WhileBool WhileBool
+ | Not WhileBool
+ | E.e: WBool e & evalb e
+
+:: WhileInt
+ = Int Int
+ | Var String
+ | (+.) infixl 6 WhileInt WhileInt
+ | E.e: WInt e & evali e
+
+class gamma g
+where
+ put :: g String Int -> g
+ get :: g String -> Int
+instance gamma Gamma
+
+:: Gamma
+emptyGamma :: Gamma
+
+class eval m :: m -> (g -> g) | gamma g
+class evali m :: m -> (g -> Int) | gamma g
+class evalb m :: m -> (g -> Bool) | gamma g
+
+instance eval WhileExpr
+instance evali WhileInt
+instance evalb WhileBool
--- /dev/null
+implementation module while
+
+import StdEnv
+
+:: Gamma :== String -> Int
+instance gamma Gamma
+where
+ put g i v = \i`->if (i == i`) v (g i)
+ get g v = g v
+
+emptyGamma :: Gamma
+emptyGamma = abort "Undefined variable"
+
+instance eval WhileExpr
+where
+ eval (i =. v) = \g->put g i (evali v g)
+ eval (If b _ t _ e) = \g->if (evalb b g) (eval t g) (eval e g)
+ eval (a :. b) = eval b o eval a
+ eval x=:(While b _ e) = \g->if (evalb b g) (eval (e :. x) g) g
+ eval Skip = id
+ eval (WExpr e) = eval e
+
+instance evali WhileInt
+where
+ evali (Int i) = const i
+ evali (Var s) = flip get s
+ evali (a +. b) = \g->evali a g + evali b g
+ evali (WInt e) = evali e
+
+instance evalb WhileBool
+where
+ evalb (Bool b) = const b
+ evalb (a ==. b) = \g->evali a g == evali b g
+ evalb (a &. b) = \g->evalb a g && evalb b g
+ evalb (Not a) = not o evalb a
+ evalb (WBool e) = evalb e
+
+Start = (eval ("a" =. Int 42 :. While (Bool False) Do ("b" =. Int 4)) emptyGamma) "a"
--- /dev/null
+definition module whileMult
+
+import while
+
+:: WMult = WMult WhileInt WhileInt
+
+(*.) infixl 7
+(*.) a b :== WInt (WMult a b)
+
+instance evali WMult
--- /dev/null
+implementation module whileMult
+
+import StdEnv
+import while
+
+instance evali WMult where evali (WMult a b) = \g->evali a g * evali b g
--- /dev/null
+definition module whileRep
+
+import while
+
+:: WRep = WRepeat WhileExpr Until WhileBool
+:: Until = Until
+
+Repeat e Until b :== WExpr (WRepeat e Until b)
+
+instance eval WRep
--- /dev/null
+implementation module whileRep
+
+import while
+
+:: WRep = WRepeat WhileExpr Until WhileBool
+
+instance eval WRep where eval (WRepeat e Until b) = eval (e :. While b Do e)
--- /dev/null
+module gadt
+
+import StdEnv
+import Data.Func
+import Data.Functor
+import Data.Either
+import Data.List
+import Data.Maybe
+import Control.Applicative
+import Control.Monad
+
+:: BM a b = {to :: a->b, fro :: b->a}
+bm = {to=id,fro=id}
+:: Expr a
+ = Lit (BM a Int) Int
+ | Var (BM a Int) String
+ | E.e: Plus (BM a e) (Expr a) (Expr a) & + e
+
+eval :: (Expr Int) -> ([(String, Int)] -> Either String Int)
+eval (Lit _ i) = const $ pure i
+eval (Var _ s) = maybe (Left $ "Undefined variable " +++ s) Right o lookup s
+eval (Plus _ a b) = \s->liftM2 (+) (eval a s) (eval b s)
+
+print :: (Expr a) -> String
+print (Lit _ i) = toString i
+print (Var _ s) = s
+print (Plus _ a b) = print a +++ " + " +++ print b
+
+Start = eval (Plus bm (Lit bm 5) (Lit bm 37)) []
--- /dev/null
+module shallow
+
+import StdEnv
+import Data.Func
+import Data.Functor
+import Data.Either
+import Data.List
+import Data.Maybe
+import Control.Applicative
+import Control.Monad
+
+:: Expr :==
+ ([(String, Int)] -> Either String Int //Evaluator
+ , String) //Printer
+
+lit :: Int -> Expr
+lit i = (const $ pure i, toString i)
+
+var :: String -> Expr
+var s =
+ ( maybe (Left $ "Undefined variable " +++ s) Right o lookup s
+ , s
+ )
+
+(+.) infixl 6 :: Expr Expr -> Expr
+(+.) (ea, pa) (eb, pb) =
+ ( \s->liftM2 (+) (ea s) (eb s)
+ , pa +++ " + " +++ pb
+ )
+
+print :: Expr -> String
+print (_, p) = p
+
+eval :: Expr [(String, Int)]-> Either String Int
+eval (e, _) s = e s
+
+Start = eval (lit 5 +. lit 37) []
--- /dev/null
+module test
+
+import Text.GenJSON
+from Data.Map import :: Map, newMap
+
+Start = JSONEncode{|*|} True map
+where
+ map :: Map Int Int
+ map = newMap
--- /dev/null
+module test
+
+import iTasks
+import StdMisc,StdDebug
+import Data.Maybe
+
+Start w = startEngine t w
+
+t = withShared () \channels->
+ forever (chooseAction [(Action "Set", ())] >>- \_->set () channels)
+ ||- tcpconnect "localhost" 8123 channels
+ {ConnectionHandlers|
+ onConnect=onConnect,
+ onData=onData,
+ onShareChange=onShareChange,
+ onDisconnect=onDisconnect}
+ where
+ onConnect acc ()
+ | not (trace_tn "onConnect") = undef
+ = (Ok "", Nothing, [], False)
+
+ onData newdata acc ()
+ | not (trace_tn "onData") = undef
+ = (Ok "", Nothing, [], False)
+
+ onShareChange acc ()
+ | not (trace_tn "onShareChange") = undef
+ = (Ok "", Nothing, [], False)
+
+ onDisconnect _ ()
+ | not (trace_tn "onDisconnect") = undef
+ = (Ok "", Nothing)