LoginSignup
3
2

More than 5 years have passed since last update.

【Haskell】case式

Last updated at Posted at 2016-10-22

Haskellのcase ofは式であるため、値と同じように扱うことができます。

let var = 100
    str = case var of
        100 -> "Hundred"
        _   -> "Otherwise"

ifと同じく、式の生成する値の型は一致させなければなりません。例えば、以下のコードはエラーとなります。

let var = 100
    str = case var of
        100 -> 100          -- 戻り値の型は Num a => a
        _   -> "Otherwise"  -- 戻り値の型は String
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2