Skip to main content

All Questions

Tagged with
5 votes
1 answer
95 views

In Frege how can I convert an String safely to a Maybe Int?

In Frege I want to convert an String to an Int, but need to handle unparsable strings too. So I guess I'm looking for something like a readMaybe function. Where do I find this? Or how can I use Java's ...
halloleo's user avatar
  • 9,924
5 votes
4 answers
249 views

In Functional Programming, why the Maybe functor is not defined as data Maybe a = Nothing | a?

I was wondering why in Haskell (and FP in general) functors such as the Maybe functor are defined as data Maybe a = Nothing | Just a Instead of simply data Maybe a = Nothing | a The second option ...
Davi Barreira's user avatar
1 vote
0 answers
89 views

Own mapMaybe does not parse

So I have the following type annotation in Haskell: mapMaybe :: (a -> b) -> Maybe a -> Maybe b And it is defined as follows: mapMaybe _ Nothing = Nothing mapMaybe f (Just x) = Just (head (...
coderodde's user avatar
  • 929
1 vote
3 answers
132 views

Accumulate a Function Over a List of Monads (Maybe)

I'm learning Haskell as a way of getting to grips with a new programming paradigm. I'm getting hung up on a specific, probably basic, issue. While I'm finding lots of documentation and other stack ...
Philip Adler's user avatar
  • 2,184
0 votes
1 answer
103 views

Wrap a partial pattern matching into a Maybe

Is there any way to wrap a partial pattern-match into a Maybe? I wish to write some code kind of like this: fromMaybe defaultValue $ do [a, b] <- mkList :: [Int] [x] <- mkList' a b :: [Int] ...
Blue Nebula's user avatar
  • 1,026
2 votes
1 answer
199 views

Inverted [Maybe a] tranverse behavior

I want to create a function that receives some items to process, returning Nothing when none of the items could be processed and Just if at least one item was processed. To me, this sounds a lot like ...
João Haas's user avatar
  • 2,068
1 vote
2 answers
270 views

Are Maybe String and Maybe Int both Monoids in Haskell?

I´ve gotten into a bit of confusion whether Maybe Int and Maybe String are both monoids in Haskell because i dont really know what functions you can apply to Int or String in terms of monoids with ...
GDash 69's user avatar
4 votes
2 answers
248 views

Combine two Just values if present, else return first Just

I want a shorter way to write this block of code as this is going to be used in multiple places in a project I am working on. Is there a library I can use which would have a function for my specific ...
AKSHAT GUPTA's user avatar
2 votes
1 answer
516 views

What is the advantage of Option/Maybe Monad over Functor?

I understand the advantage of IO monad and List Monad over Functor, however, I don't understand the advantage of Option/Maybe Monad over Functor. Is that simply the integration of types of the ...
SmoothTraderKen's user avatar
1 vote
1 answer
149 views

Non-exhaustive patterns in function - Maybe type [duplicate]

In the following function definition I am getting Non-exhaustive patterns in function tapChar. What am I missing? reverseTap :: DaPhone -> Char -> [(Digit, Presses)] reverseTap phone s | ...
smuthu06's user avatar
4 votes
1 answer
457 views

How can I handle Nothing branch of maybe monad gracefully?

data Union = F Float | I Int | S String getUnionFromString :: String -> Union getUnionFromString str = case (readMaybe str :: Maybe Int) of Just i -> I i Nothing -> ...
lunuy lunuy's user avatar
4 votes
4 answers
788 views

How to recursively iterate over a list with Maybe objects in Haskell

I am trying to create a function justifyList that takes a list of Maybe objects ([Maybe a]) and return a list of all objects of Just type, discarding any element that is Nothing in the parameter list. ...
MarkusAnd's user avatar
  • 782
0 votes
1 answer
423 views

Finding max of a list of Maybe values in Haskell using Higher Order Functions

I am trying to use higher level order functions to take a list of Maybe values and return a max of type int but for some reason I can only return a Maybe value. For example this works: max' iL = foldl ...
flavalv's user avatar
0 votes
1 answer
139 views

What is This More General Almost-Traversal Operation

Trying to wrap my mind around traversals - or maybe something slightly different, in this case. I understand a traversal to be an operation that performs an applicative operation (or effect) over a ...
Bondolin's user avatar
  • 3,041
-1 votes
1 answer
148 views

How to stop Maybe from being passed into another function in Haskell [closed]

I have already looked at this answer, but it is unclear to me how to apply it in my situation. I have the following function: designC :: DesignC -> Maybe CDef -> String designC FirstString _ = &...
PaulD's user avatar
  • 23

15 30 50 per page
1
2 3 4 5
17