1
我在psci repl中執行此操作。這是我的函數:如何在purescript中匹配列表頭部和尾部
$> import Data.List
$> let f (x:xs) = x
$> let f Nil = Nil
$> let a = 1:2:3:Nil
$> f a
我得到這個錯誤:
Could not match type
Int
with type
List t0
while trying to match type List Int
with type List (List t0)
while checking that expression a
has type List (List t0)
in value declaration it
where t0 is an unknown type
我理解這種情況正在發生,因爲我的功能f
沒有返回List Int
簽名。但是,我如何在repl中聲明一個?
我該如何解決這個問題,以便'f'返回'Maybe'類型? – dopatraman
'f(x:xs)= Just x' 'f Nil = Nothing' –