git.iko.soy/rowtype-yoga/purescript-native
on cd4c708 help sign in
68 lines 1.1 kB history raw
1module Main where
3import Prelude
4import Control.Monad.Eff.Console (log)
6data Maybe a = Nothing | Just a
8instance functorMaybe :: Functor Maybe where
9 map f Nothing = Nothing
10 map f (Just x) = Just (f x)
12instance applyMaybe :: Apply Maybe where
13 apply (Just f) (Just x) = Just (f x)
14 apply _ _ = Nothing
16instance applicativeMaybe :: Applicative Maybe where
17 pure = Just
19instance bindMaybe :: Bind Maybe where
20 bind Nothing _ = Nothing
21 bind (Just a) f = f a
23instance monadMaybe :: Monad Maybe
25test1 = \_ -> do
26 Just "abc"
28test2 = \_ -> do
29 x <- Just 1.0
30 y <- Just 2.0
31 Just (x + y)
33test3 = \_ -> do
34 Just 1.0
35 Nothing :: Maybe Number
36 Just 2.0
38test4 mx my = do
39 x <- mx
40 y <- my
41 Just (x + y + 1.0)
43test5 mx my mz = do
44 x <- mx
45 y <- my
46 let sum = x + y
47 z <- mz
48 Just (z + sum + 1.0)
50test6 mx = \_ -> do
51 let
52 f :: forall a. Maybe a -> a
53 f (Just x) = x
54 Just (f mx)
56test8 = \_ -> do
57 Just (do
58 Just 1.0)
60test9 = \_ -> (+) <$> Just 1.0 <*> Just 2.0
62test10 _ = do
63 let
64 f x = g x * 3.0
65 g x = f x / 2.0
66 Just (f 10.0)
68main = log "Done"