在Haskell,有办法限制mona条码a
。 满足某类限制?
我将probabilistic modeling example from support。 因为它将更改<代码>数据分布至 (Ord a) => 分发
。 随着这一变化,我有以下错误:
...probabilisticModeling.hs:42:13:
Could not deduce (Ord a) from the context ()
arising from a use of `always
at ...probabilisticModeling.hs:42:13-18
Possible fix:
add (Ord a) to the context of the type signature for `return
In the expression: always
In the definition of `return : return = always
In the instance declaration for `Monad Distribution
事实上,<代码>always/return
的类型是:(Ord a) => a-> distribution a
。 是否有一种方式,我可以采用一个手法<代码>Distribution,但强制实施该mon的“条码”(Ord a)? 我尝试:
instance Monad Distribution where
(>>=) = bind
return :: (Ord a) => a -> Distribution a = always
But I get the error:
...probabilisticModeling2.hs:48:4:
Pattern bindings (except simple variables) not allowed in instance declarations
return :: (Ord a) => a -> Distribution a = always
Failed, modules loaded: none.
因此,可以选择一个mon子(M a
),但限制a
,限制例如。 或d a
?
Thanks.