Maybe列表的Hackage文档可以作为Maybe的一个typeclasses折叠。它还列出了以下功能:为什么我不能在Haskell中执行`null(Just 5)`?
null :: Maybe a -> Bool
它甚至还列出了这一功能的实现(从Foldable
):
null :: t a -> Bool
null = foldr (\_ _ -> False) True
...这似乎是相当合理的。它也适用:如果我import qualified Data.Foldable
,我可以在Maybe值上使用foldr
。
然而,当我尝试调用null
上也许,哈斯克尔认为我想用设计列表空:
Prelude> :t null
null :: [a] -> Bool
Prelude> null Nothing
<interactive>:3:6:
Couldn't match expected type `[a0]' with actual type `Maybe a1'
In the first argument of `null', namely `Nothing'
In the expression: null Nothing
In an equation for `it': it = null Nothing
我知道有isJust
,我只是想知道如何调用功能如null
任何折叠。
什么GHC /基础版本您使用的?因为是与基础4.8.x是['TA - > Bool'](https://hackage.haskell.org/package/base-4.8.1.0/docs/Prelude.html#v:null),但['空'曾经是'[A] - > Bool'](https://hackage.haskell.org/package/base-4.7.0.1/docs/Prelude.html#v:null) – Carsten
@Carsten是的,这正是它 - Ubuntu Vivid显然仍在发布[ghc 7.6.3](http://packages.ubuntu.com/vivid/ghc),该版本于2013年4月发布,并具有较旧版本的基础。 –
噢,抱歉 - 看到你的答案下旬 - 顺便说一句,你可以使用[赫伯特·V. Riedels PPA来源(https://launchpad.net/~hvr/+archive/ubuntu/ghc):d – Carsten