git.iko.soy/rowtype-yoga/purescript-native
on e82e607 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 (<$>) f Nothing = Nothing
9 (<$>) f (Just x) = Just (f x)
11instance applyMaybe :: Apply Maybe where
12 (<*>) (Just f) (Just x) = Just (f x)
13 (<*>) _ _ = Nothing
15instance applicativeMaybe :: Applicative Maybe where
16 pure = Just
18instance bindMaybe :: Bind Maybe where
19 (>>=) Nothing _ = Nothing
20 (>>=) (Just a) f = f a
22instance monadMaybe :: Prelude.Monad Maybe
24test1 = \_ -> do
25 Just "abc"
27test2 = \_ -> do
28 (x : _) <- Just [1, 2, 3]
29 (y : _) <- Just [4, 5, 6]
30 Just (x + y)
32test3 = \_ -> do
33 Just 1
34 Nothing :: Maybe Number
35 Just 2
37test4 mx my = do
38 x <- mx
39 y <- my
40 Just (x + y + 1)
42test5 mx my mz = do
43 x <- mx
44 y <- my
45 let sum = x + y
46 z <- mz
47 Just (z + sum + 1)
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)
59test9 = \_ -> (+) <$> Just 1 <*> Just 2
61test10 _ = do
62 let
63 f x = g x * 3
64 g x = f x / 2
65 Just (f 10)
67main = Debug.Trace.trace "Done"