From: Mart Lubbers Date: Wed, 24 Jul 2019 12:08:10 +0000 (+0200) Subject: upd X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=90c1712ad176aff581b04e1e0915acda319226d2;p=clean-tests.git upd --- diff --git a/parseclass/expr.icl b/parseclass/expr.icl new file mode 100644 index 0000000..6d5dad5 --- /dev/null +++ b/parseclass/expr.icl @@ -0,0 +1,76 @@ +module expr + +import StdEnv + +import Control.Applicative +import Control.Monad +import Data.Error +import Data.Func +import Data.Functor +import Text.Parsers.Simple.Core +import Text.Parsers.Simple.Chars + +class expr e where + lit :: a -> e a | toString a + (+.) infixl 6 :: (e a) (e a) -> e a | + a +class div e where + (/.) infixl 7 :: (e a) (e a) -> e a | /, ==, zero a +class eq e where + (==.) infix 4 :: (e a) (e a) -> e Bool | == a + +:: Print a = P String +runPrint :: (Print a) -> String +runPrint (P a) = a +instance expr Print where + lit a = P (toString a) + (+.) (P a) (P b) = P (a +++ "+" +++ b) +instance div Print where + (/.) (P a) (P b) = P (a +++ "/" +++ b) +instance eq Print where + (==.) (P a) (P b) = P (a +++ "==" +++ b) + +:: Eval a = E a +runEval :: (Eval a) -> a +runEval (E a) = a +instance expr Eval where + lit a = E a + (+.) (E a) (E b) = E (a + b) +instance div Eval where + (/.) (E a) (E b) + | b == zero = E zero + = E (a / b) +instance eq Eval where + (==.) (E a) (E b) = E (a == b) + +:: EvalM a :== MaybeError String a +runEvalM :: (EvalM a) -> MaybeError String a +runEvalM a = a +instance expr (MaybeError String) where + lit a = pure a + (+.) l r = (+) <$> l <*> r +instance div (MaybeError String) where + (/.) l r = (/) <$> l <*> (r >>= \v->if (v == zero) (Error "div0") (pure v)) +instance eq (MaybeError String) where + (==.) l r = (==) <$> l <*> r + +pToken c = pSatisfy ((==)c) +class parseExpr a :: Parser Char a +instance parseExpr a:: parseExpr +parseExpr :: Parser Char (v a) | expr, div v & parsable, ==, +, /, zero, toString a +parseExpr = foldr ($) parseBasic + [ flip pChainl1 (pToken '+' $> (+.)) + , flip pChainl1 (pToken '/' $> (/.)) + ] +where + parseBasic = lit <$> parsable + +class parsable a :: Parser Char a +instance parsable Int where parsable = foldl (\a b->10*a+digitToInt b) 0 <$> some pDigit + +Start :: Either [Error] (Print Int) +Start = parse parseExpr ['42+42'] +/*Start = (runPrint e, runEval e, runEvalM e, parse ) +where + e :: v Bool | expr, div, eq v + e = lit 39 +. lit 3 /. lit 0 ==. lit 4 +*/ diff --git a/test.icl b/test.icl index 99d51e1..06b0dec 100644 --- a/test.icl +++ b/test.icl @@ -1,9 +1,65 @@ module test +//import StdEnv +//import Data.Error +//import Data.Maybe +//import Network.IP +//import System.Socket +//import System.Socket.Ipv4 +////import System.Select +// +import Data.Map => qualified get, updateAt +import Data.Map.GenJSON +import Data.Func import iTasks -import iTasks.Extensions.DateTime -Start w = doTasks (onStartup t) w +Start w = doTasks t2 w -t :: Task Int -t = throw "bork" +t2 = enterInformation "bork" [] + >>* [OnAction ActionOk $ ifValue ((==)42) return] + +t = parallel + [(Embedded, + \stl->appendTask Embedded (\_->viewInformation "int" [] 42 <<@ markActive <<@ markActive) stl + >>= \tid->viewInformation "go" [] "go" @! 42 +// >>* [OnAction ActionOk $ always $ set +// ([(tid, put "answer" "42" (singleton "bork" "bork"))]) +// (sdsFocus {onlyIndex=Nothing,onlyTaskId=Just [tid],onlySelf=False,includeValue=True,includeAttributes=True,includeProgress=True} stl)] +// >>= \_->viewSharedInformation "parallel task list" [] +// (sdsFocus {onlyIndex=Nothing,onlyTaskId=Nothing,onlySelf=False,includeValue=True,includeProgress=True,includeAttributes=True} stl) +// @! 42 +// ),(Embedded, \stl->viewSharedInformation "parallel task list" [] +// (sdsFocus {onlyIndex=Nothing,onlyTaskId=Nothing,onlySelf=False,includeValue=True,includeProgress=True,includeAttributes=True} stl) +// @! 42 + )] [] +// [OnAction (Action "bork") $ ifValue (\v->not (v =: [])) +// \_->(Embedded, \stl-> +// get (sdsFocus defaultValue stl) >>= \(_, [_,{TaskListItem|taskId}:_])-> +// set (singleton "title" "true") +// (sdsFocus taskId (taskListEntryMeta stl)) @! ()) +// set [(taskId, singleton "title" "true")] +// (sdsFocus listFilter stl) @! ())] + <<@ ArrangeWithTabs True +where + markActive = ApplyAttribute "class" "focus" + + +//import StdGeneric +// +//generic g a :: a +// +//g{|*|} = 42 + +//Start :: *World -> (MaybeOSError String, *World) +//Start w +// = case socket SocketStream w of +// (Error e, w) = (Error e, w) +// (Ok sockfd, w) +// #! (merr, sockfd) = connect {ipv4_socket_port=8124,ipv4_socket_addr=Just (fromString "127.0.0.1")} sockfd +// | isError merr = (liftError merr, w) +// #! (merr, sockfd) = recv 128 [] sockfd +// | isError merr = (merr, w) +// # (Ok msg) = merr +// # (merr, w) = close sockfd w +// | isError merr = (liftError merr, w) +// = (Ok msg, w)