-
[clean-tests.git] / old / dyneditors / DynEditorExample.icl
1 module DynEditorExample
2
3 import Data.Func, Data.Functor, Data.Maybe
4 import iTasks, iTasks.UI.Editor.Modifiers
5 import DynamicEditor
6
7 // non-typesafe expression
8 :: Expr = IntLit Int | RealLit Real | Plus Expr Expr | ToInt Expr | ToReal Expr | Eq Expr Expr
9
10 // expression with phantom type
11 :: TypedExpr a =: TypedExpr Expr
12
13 derive class iTask Expr, TypedExpr
14
15 dslEditor :: DynamicEditor (TypedExpr a)
16 dslEditor = DynamicEditor
17 ( [ functionConsDyn "plus" "plus"
18 ( dynamic \(TypedExpr x) (TypedExpr y) -> TypedExpr (Plus x y) ::
19 A.b: (TypedExpr b) (TypedExpr b) -> TypedExpr b
20 )
21 , functionCons "toInt" "to integer" toIntExpr
22 , functionCons "toReal" "to decimal" toRealExpr
23 , customEditorCons "int" "(enter integer)"
24 (bijectEditorValue (\(TypedExpr (IntLit i)) -> i) intLit gEditor{|*|})
25 , customEditorCons "real" "(enter decimal)"
26 (bijectEditorValue (\(TypedExpr (RealLit r)) -> r) realLit gEditor{|*|})
27 , functionConsDyn "eq" "are equal"
28 ( dynamic \(TypedExpr x) (TypedExpr y) -> TypedExpr (Eq x y) ::
29 A.b: (TypedExpr b) (TypedExpr b) -> TypedExpr Bool
30 )
31 ]
32 )
33 where
34 toIntExpr :: (TypedExpr Real) -> TypedExpr Int
35 toIntExpr (TypedExpr x) = TypedExpr (ToInt x)
36
37 toRealExpr :: (TypedExpr Int) -> TypedExpr Real
38 toRealExpr (TypedExpr x) = TypedExpr (ToReal x)
39
40 intLit :: Int -> TypedExpr Int
41 intLit i = TypedExpr (IntLit i)
42
43 realLit :: Real -> TypedExpr Real
44 realLit r = TypedExpr (RealLit r)
45
46 // possible results can be Int, Real
47 // Bool does not work yet
48 enterExpr :: Task (Maybe (DynamicEditorValue (TypedExpr Int)))
49 enterExpr = enterInformation () [EnterUsing id $ dynamicEditor dslEditor] >&>
50 viewSharedInformation () [ViewAs $ fmap $ toValue dslEditor]
51
52 Start world = doTasks enterExpr world