fixed Maybe ('a -> 'a) bug. Pattern matching still wonky, will have to redo
This commit is contained in:
parent
fce54e7899
commit
62724964d7
3 changed files with 579 additions and 97 deletions
48
test_program
48
test_program
|
|
@ -1,50 +1,10 @@
|
|||
-- data Bool () where {
|
||||
-- True : Bool ()
|
||||
-- False : Bool ()
|
||||
-- };
|
||||
--
|
||||
-- data List ('a) where {
|
||||
-- Nil : List ('a)
|
||||
-- Cons : ('a) -> List ('a) -> List ('a)
|
||||
-- };
|
||||
|
||||
data Maybe ('a) where {
|
||||
Nothing : Maybe ('a)
|
||||
Just : 'a -> Maybe ('a)
|
||||
};
|
||||
|
||||
-- id : 'a -> 'a ;
|
||||
-- id x = x ;
|
||||
id : 'a -> 'a ;
|
||||
id x = x ;
|
||||
|
||||
-- main : Maybe ('a -> 'a) ;
|
||||
-- main = Just id;
|
||||
|
||||
-- data Either ('a 'b) where {
|
||||
-- Left : 'a -> Either ('a 'b)
|
||||
-- Right : 'b -> Either ('a 'b)
|
||||
-- };
|
||||
|
||||
-- safeHead : List ('a) -> Maybe ('a) ;
|
||||
-- safeHead xs =
|
||||
-- case xs of {
|
||||
-- Nil => Nothing ;
|
||||
-- Cons x xs => Just x
|
||||
-- };
|
||||
|
||||
-- main : Maybe (_Int) ;
|
||||
-- main = safeHead (Cons 0 (Cons 1 Nil)) ;
|
||||
--
|
||||
-- maybeToEither : Either ('a 'b) -> Maybe ('a) ;
|
||||
-- maybeToEither e =
|
||||
-- case e of {
|
||||
-- Left y => Nothing ;
|
||||
-- Right x => Just x
|
||||
-- };
|
||||
|
||||
-- Bug. f not included in the case-expression context
|
||||
fmap : ('a -> 'b) -> Maybe ('a) -> Maybe ('b) ;
|
||||
fmap f x =
|
||||
case x of {
|
||||
Just x => Just (f x) ;
|
||||
Nothing => Nothing
|
||||
}
|
||||
main : Maybe ('a -> 'a) ;
|
||||
main = Just id ;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue