added more manual tests
This commit is contained in:
parent
24007313cb
commit
88a4a934b8
6 changed files with 67 additions and 19 deletions
3
Makefile
3
Makefile
|
|
@ -28,6 +28,9 @@ test :
|
||||||
./language ./sample-programs/basic-3
|
./language ./sample-programs/basic-3
|
||||||
./language ./sample-programs/basic-4
|
./language ./sample-programs/basic-4
|
||||||
./language ./sample-programs/basic-5
|
./language ./sample-programs/basic-5
|
||||||
|
./language ./sample-programs/basic-6
|
||||||
|
./language ./sample-programs/basic-7
|
||||||
|
./language ./sample-programs/basic-8
|
||||||
|
|
||||||
run :
|
run :
|
||||||
cabal -v0 new-run language -- "test_program"
|
cabal -v0 new-run language -- "test_program"
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
-- double : _Int -> _Int ;
|
double : _Int -> _Int ;
|
||||||
-- double n = n + n;
|
double n = n + n;
|
||||||
|
|
||||||
id : 'a -> 'a ;
|
id : 'a -> 'a ;
|
||||||
id x = x ;
|
id x = x ;
|
||||||
|
|
||||||
main : ('a -> 'b -> 'c) ;
|
main : _Int ;
|
||||||
main = id ;
|
main = id double 5;
|
||||||
|
|
|
||||||
10
sample-programs/basic-6
Normal file
10
sample-programs/basic-6
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
data Bool () where {
|
||||||
|
True : Bool ()
|
||||||
|
False : Bool ()
|
||||||
|
};
|
||||||
|
|
||||||
|
main : Bool () -> _Int ;
|
||||||
|
main b = case b of {
|
||||||
|
False => 0;
|
||||||
|
True => 0
|
||||||
|
}
|
||||||
10
sample-programs/basic-7
Normal file
10
sample-programs/basic-7
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
data Bool () where {
|
||||||
|
True : Bool ()
|
||||||
|
False : Bool ()
|
||||||
|
};
|
||||||
|
|
||||||
|
ifThenElse : Bool () -> 'a -> 'a -> 'a;
|
||||||
|
ifThenElse b if else = case b of {
|
||||||
|
True => if;
|
||||||
|
False => else
|
||||||
|
}
|
||||||
24
sample-programs/basic-8
Normal file
24
sample-programs/basic-8
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
data Maybe ('a) where {
|
||||||
|
Nothing : Maybe ('a)
|
||||||
|
Just : 'a -> Maybe ('a)
|
||||||
|
};
|
||||||
|
|
||||||
|
fromJust : Maybe ('a) -> 'a ;
|
||||||
|
fromJust a =
|
||||||
|
case a of {
|
||||||
|
Just a => a
|
||||||
|
};
|
||||||
|
|
||||||
|
fromMaybe : 'a -> Maybe ('a) -> 'a ;
|
||||||
|
fromMaybe a b =
|
||||||
|
case b of {
|
||||||
|
Just a => a;
|
||||||
|
Nothing => a
|
||||||
|
};
|
||||||
|
|
||||||
|
maybe : 'b -> ('a -> 'b) -> Maybe ('a) -> 'b;
|
||||||
|
maybe b f ma =
|
||||||
|
case ma of {
|
||||||
|
Just a => f a;
|
||||||
|
Nothing => b
|
||||||
|
}
|
||||||
31
test_program
31
test_program
|
|
@ -1,23 +1,24 @@
|
||||||
-- data Bool () where {
|
|
||||||
-- True : Bool ()
|
|
||||||
-- False : Bool ()
|
|
||||||
-- };
|
|
||||||
|
|
||||||
data Maybe ('a) where {
|
data Maybe ('a) where {
|
||||||
Nothing : Maybe ('a)
|
Nothing : Maybe ('a)
|
||||||
Just : 'a -> Maybe ('a)
|
Just : 'a -> Maybe ('a)
|
||||||
};
|
};
|
||||||
|
|
||||||
-- main : Bool () -> Maybe (Bool ()) ;
|
fromJust : Maybe ('a) -> 'a ;
|
||||||
-- main x =
|
fromJust a =
|
||||||
-- case x of {
|
|
||||||
-- True => Nothing;
|
|
||||||
-- False => Just True
|
|
||||||
-- };
|
|
||||||
|
|
||||||
fun : Maybe ('a) -> 'a ;
|
|
||||||
fun a =
|
|
||||||
case a of {
|
case a of {
|
||||||
Just c => c
|
Just a => a
|
||||||
};
|
};
|
||||||
|
|
||||||
|
fromMaybe : 'a -> Maybe ('a) -> 'a ;
|
||||||
|
fromMaybe a b =
|
||||||
|
case b of {
|
||||||
|
Just a => a;
|
||||||
|
Nothing => a
|
||||||
|
};
|
||||||
|
|
||||||
|
maybe : 'b -> ('a -> 'b) -> Maybe ('a) -> 'b;
|
||||||
|
maybe b f ma =
|
||||||
|
case ma of {
|
||||||
|
Just a => f a;
|
||||||
|
Nothing => b
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue