summaryrefslogtreecommitdiff
path: root/examples/passing/Guards.purs
blob: af68c40c0cece4c4d066862a79bfee22a205296c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module Main where

foreign import jsMod
  """
  function jsMod(x) {
    return function (y) {
      return x % y;
    };
  }
  """ :: Number -> Number -> Number

infixl 7 %
(%) = jsMod

collatz = \x -> case x of
  y | y % 2 == 0 -> y / 2
  y -> y * 3 + 1

-- Guards have access to current scope
collatz2 = \x y -> case x of
  z | y > 0 -> z / 2
  z -> z * 3 + 1

min :: forall a. (Ord a) => a -> a -> a
min n m | n < m     = n
        | otherwise = m

max :: forall a. (Ord a) => a -> a -> a
max n m = case unit of
  _ | m < n     -> n
    | otherwise -> m

testIndentation :: Number -> Number -> Number
testIndentation x y | x > 0
  = x + y
                    | otherwise
  = y - x

main = Debug.Trace.trace $ min "Done" "ZZZZ"