今日はこの辺で

module Sample where 

    • 関数定義

foo x y = x + y
hoge = 2

    • 分岐
    • 引数パターンマッチング

boo 1 = "a"
boo 2 = "b"

func0 0 = 1
func0 n = n * func0(n-1)

    • ガード

func1 a b |a && b == 1 = "0!"
          |a          = "1!"
          |otherwise  = "2!"

    • if

func2 n = if n == 0
            then  "OK"
            else  "NG"

    • case

func3 n = case n of
  0->"a"
  1->"b"
  _->"c"

    • 補助関数
    • インデントに注意
    • where

func4 a b = c + d
  where
    c = a * b
    d = a * b

    • 同let

func5 a b = let
  c = a * b
  d = a * b
  in c + d

func6 a b = iter a 0
  where
    iter c d
      |c < b = (d,c)
      |otherwise = iter (c-b) (d+1)

func7 a b = a * b

f0 = \x->x + 1

func8 a = a + 1
func9 a b = a + b
func10 a = a - 1