git.iko.soy/rowtype-yoga/purescript-backend-optimizer
on main help sign in
61 lines 1.2 kB history raw
1module Snapshot.CaseGuarded where
3import Prelude
4import Data.Maybe (Maybe(..))
5import Data.Either (Either(..))
7test1 :: Int -> String
8test1 = case _ of
9 n
10 | n < 1 -> "n: " <> show n
11 x
12 | x > 1
13 , x < 100 -> "1 < x < 100: " <> show x
15 | x > 1
16 , x < 50 -> "1 < x < 50: " <> show x
18 | otherwise -> "catch"
20newtype NInt = NInt Int
22test2 :: NInt -> Int
23test2 = case _ of
24 NInt i | i < 1 -> i
25 NInt i | i > 1 -> i
26 NInt i | i == 1 -> 1
27 NInt _ -> 0
29data Product3 a b c = Product3 a b c
31test3 :: Product3 Int Int Int -> Int
32test3 = case _ of
33 Product3 a b _ | a == b -> a
34 Product3 a b c | c == b -> a
35 Product3 a _ c | a == c -> c
36 Product3 _ b _ -> b
38test4
39 :: { a :: Int, b :: Int, c :: Int }
40 -> { d :: Int, e :: Int, f :: Int }
41 -> Int
42test4 = case _, _ of
43 { a: 1 }, { d: 1 } -> 1
44 _, { d: 2 } -> 2
45 _, { d: 3 } -> 3
46 { a: 1 }, { d: 4 } -> 4
47 { a: 1 }, { d: 5 } -> 5
48 { a: 2 }, { d: 1 } -> 6
49 { c }, { e, d: 4 }
50 | c == e -> 7
51 | c < e -> 8
52 | c > e -> 9
53 { b: 2 }, { d: 1, f: 10 } -> 10
54 { c }, { f } -> 11 + c + f
56test5 :: Maybe (Either Int Int) -> Int
57test5 = case _ of
58 Just x
59 | Right y <- x -> y
60 | Left 2 <- x -> 4
61 _ -> 5