maybe

Using Maybe type in Haskell

给你一囗甜甜゛ 提交于 2019-11-27 08:34:09
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 -> ... arsenm You could use Data.Maybe.fromMaybe , which takes a Maybe a and a value to use if it is Nothing . You could use the unsafe Data.Maybe.fromJust , which will just crash if the value is Nothing . You likely want to keep things in Maybe . If you wanted to add an

Accessing scala.None from Java

懵懂的女人 提交于 2019-11-26 18:33:51
问题 How can you access scala.None from Java? The last line causes the compiler to die with "type scala.None does not take parameters". import scala.Option; import scala.Some; import scala.None; final Option<String> object1 = new Some<String>("Hi there"); final Option<String> object2 = new None<String>(); This fails with "cannot find symbol constructor None()": final Option<String> object2 = new None(); This fails with "cannot find symbol variable None": final Option<String> object2 = None; In

Using Maybe type in Haskell

北战南征 提交于 2019-11-26 14:14:39
问题 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. 回答1: Alternatively you can pattern match: case maybeValue of Just value -> ... Nothing -> ... 回答2: You could use Data.Maybe.fromMaybe , which takes a Maybe a and a value to use if it is Nothing . You could use the unsafe Data.Maybe.fromJust , which will

Operating on a return from a Maybe that contains “Just”

∥☆過路亽.° 提交于 2019-11-26 08:51:51
I have a function that has a return type of Maybe ([(Int,Int)],(Int,Int)) I would like to call this from another function and perform an operation on the data. However, the return value is contained within Just . The second method takes ([(Int,Int)],(Int,Int)) and therefore will not accept Just ([(Int,Int)],(Int,Int)) . Is there a way I can trim the Just before applying the second method? I don't fully understand the use of Just within Maybe - however, I have been told that the return type for the first Method must be Maybe . Thomas M. DuBuisson There are several solutions to your problem, all

Operating on a return from a Maybe that contains “Just”

百般思念 提交于 2019-11-26 02:01:53
问题 I have a function that has a return type of Maybe ([(Int,Int)],(Int,Int)) I would like to call this from another function and perform an operation on the data. However, the return value is contained within Just . The second method takes ([(Int,Int)],(Int,Int)) and therefore will not accept Just ([(Int,Int)],(Int,Int)) . Is there a way I can trim the Just before applying the second method? I don\'t fully understand the use of Just within Maybe - however, I have been told that the return type