本文介绍了在Haskell中使用Maybe类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Haskell中使用Maybe类型。我查找了返回Maybe的关键值数组。如何访问由Maybe包装的数据?例如,我想将Maybe包含的整数与另一个整数相加。 另外你可以匹配模式:

  case $V $ $ b $值只是价值 - > ... 
无 - > ...


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 example I want to add the integer contained by Maybe with another integer.

解决方案

Alternatively you can pattern match:

case maybeValue of
  Just value -> ...
  Nothing    -> ...

这篇关于在Haskell中使用Maybe类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 07:55