0
有沒有一種方法可以創建一個函數,包含不同模式的多個定義,包括在沒有其他函數的語句模式匹配時執行的函數?Haskell函數模式'其他'
例如爲:
someFunc (pattern1) = def1
someFunc (pattern2) = def2
someFunc (<otherwise/all other possible values>) = def3
或者,如果這是不可能的,怎麼能實現?
提前致謝!
此致敬禮, Skyfe。
但是,如果兩個定義都是可行的呢?它會自動使用符合輸入值的第一個遇到的定義嗎?因爲在你的例子中,一個Just value作爲參數會使第二個定義與通配符合適嗎? – user2999349 2014-10-10 14:44:45
模式按您定義的順序進行嘗試。因此'isJust _ = False';只是(Just _)= True'不會是相同的功能。 – bheklilr 2014-10-10 14:45:52
好吧,我明白了,謝謝! – user2999349 2014-10-10 14:46:24