git.iko.soy/rowtype-yoga/purescript-native
on ebbc4e4 help sign in
67 lines 1.1 kB history raw
1module Main where
3import Prelude
5data Maybe a = Nothing | Just a
7instance functorMaybe :: Functor Maybe where
8 map f Nothing = Nothing
9 map f (Just x) = Just (f x)
11instance applyMaybe :: Apply Maybe where
12 apply (Just f) (Just x) = Just (f x)
13 apply _ _ = Nothing
15instance applicativeMaybe :: Applicative Maybe where
16 pure = Just
18instance bindMaybe :: Bind Maybe where
19 bind Nothing _ = Nothing
20 bind (Just a) f = f a
22instance monadMaybe :: Prelude.Monad Maybe
24test1 = \_ -> do
25 Just "abc"
27test2 = \_ -> do
28 x <- Just 1.0
29 y <- Just 2.0
30 Just (x + y)
32test3 = \_ -> do
33 Just 1.0
34 Nothing :: Maybe Number
35 Just 2.0
37test4 mx my = do
38 x <- mx
39 y <- my
40 Just (x + y + 1.0)
42test5 mx my mz = do
43 x <- mx
44 y <- my
45 let sum = x + y
46 z <- mz
47 Just (z + sum + 1.0)
49test6 mx = \_ -> do
50 let
51 f :: forall a. Maybe a -> a
52 f (Just x) = x
53 Just (f mx)
55test8 = \_ -> do
56 Just (do
57 Just 1.0)
59test9 = \_ -> (+) <$> Just 1.0 <*> Just 2.0
61test10 _ = do
62 let
63 f x = g x * 3.0
64 g x = f x / 2.0
65 Just (f 10.0)
67main = Control.Monad.Eff.Console.log "Done"