Using Maybe type in Haskell

后端 未结 6 2004
孤独总比滥情好
孤独总比滥情好 2020-12-01 13:46

I\'m trying to utilize the Maybe type in Haskell. I have a lookup for key, value tuples that returns a Maybe. How do I access the data that was wrapped by Maybe? For exam

6条回答
  •  醉话见心
    2020-12-01 14:27

    Sorry, I should have googled better.

    using the fromMaybe function is exactly what I need. fromMaybe will return the value in Maybe if it is not nothing, otherwise it will return a default value supplied to fromMaybe.

    http://www.haskell.org/ghc/docs/6.12.2/html/libraries/base-4.2.0.1/Data-Maybe.html

提交回复
热议问题