Haskell 使用智能构造函数进行模式匹配
有没有一种方法可以在其模块之外与智能构造函数进行模式匹配 大概是这样的:Haskell 使用智能构造函数进行模式匹配,haskell,Haskell,有没有一种方法可以在其模块之外与智能构造函数进行模式匹配 大概是这样的: import MyModule (thing) fn (thing 3) = True 无法写出以下内容: fn (Thing 3) = True 其中thing是thing的智能构造函数在MyModule中定义并导出它: extract :: Thing -> Int extract (Thing x) = x 使用扩展名: {-# LANGUAGE ViewPatterns #-} fn :: Thin
import MyModule (thing)
fn (thing 3) = True
无法写出以下内容:
fn (Thing 3) = True
其中
thing
是thing
的智能构造函数在MyModule
中定义并导出它:
extract :: Thing -> Int
extract (Thing x) = x
使用扩展名:
{-# LANGUAGE ViewPatterns #-}
fn :: Thing -> Bool
fn (extract -> 3) = True
可能重复的