Variables in Haskell

后端 未结 3 941
再見小時候
再見小時候 2021-01-18 20:43

Why does the following Haskell script not work as expected?

find :: Eq a => a -> [(a,b)] -> [b]
find k t = [v | (k,v) <- t]

Giv

3条回答
  •  盖世英雄少女心
    2021-01-18 21:28

    You can only pattern match on literals and constructors.
    You can't match on variables. Read more here.

    That being said, you may be interested in view patterns.

提交回复
热议问题