我hvae只是invended的Maybe
以下替代定義:如何使Maybe工作的這個備選定義?
type Maybe' a = forall b. (b -> (a -> b) -> b)
just :: a -> Maybe' a
just a = \d f -> f a
nothing :: Maybe' a
nothing = const
bind :: Maybe' a -> (a -> Maybe' b) -> Maybe' b
bind ma f = ma nothing (\a -> f a)
問題是我不能添加以下實例聲明
instance Monad (Maybe') where
return = just
a >>= f = bind a f
的錯誤信息是:
Type synonym Maybe' should have 1 argument, but has been given none
有什麼方法可以解決?
Ahem,抱歉是那個僧侶,但你還沒有發明一個新的也許,你已經重新發現了它的**教會編碼** - 例如見這裏 - https://gist.github.com/rampion/2176199 –
我用Google搜索「教會編碼也許」的方式獨立提出了相同的答案。我沒有偷你的答案。 – nponeccop
一個有趣的事實:被視爲一個命題,你的'Maybe(A)'是'FALSE - > NOT(NOT(A))',它與'TRUE OR'相同' - 一個單位類型的析取' )'並鍵入'A'。 –