Haskellのガード勉強中

before

between :: Int -> Int -> Int -> Bool
between x y z = 
    if ((y < x && x < z) || (z < x && x < y)) then
        True
    else
        False

after

between :: Int -> Int -> Int -> Bool
between x y z  
    | y < x && x < z = True
    | z < x && x < y = True
    | otherwise = False

before

progress_turn :: Int -> Int -> Int -> [Int]
progress_turn x y z =
    if (between x y z) then
        [x, 0, 0]
    else 
        if (between y x z) then
            [0, y, 0]
        else
            [0, 0, z]

after

progress_turn :: Int -> Int -> Int -> [Int]
progress_turn x y z
    | (between x y z) = [x, 0, 0]
    | (between y x z) = [0, y, 0]
    | otherwise = [0, 0, z]

before

your_score :: [Int] -> [Int] -> Int
your_score cur_score new_score = 
    if (x == y && x == z) then 
        0
    else 
        if (x == y || x == z) then
             1
        else 
            if (between x y z) then
                2
            else
                if (y == z) then
                    -2
                else
                    -1

    where [x, y, z] = [x + y | (x, y)<-(zip cur_score new_score)]

after

your_score :: [Int] -> [Int] -> Int
your_score cur_score new_score 
    | (x == y && x == z) = 0
    | (x == y || x == z) = 1
    | (between x y z) = 2
    | (y == z) = -2
    | otherwise = -1
    where [x, y, z] = [x + y | (x, y)<-(zip cur_score new_score)]

おおお、ガードを使うととてもきれいに書けるな。