import Control.Arrow import Control.Applicative h :: (Applicative f) => (a -> f b) -> (a -> f c) -> a -> f (b, c) h = liftA2 (liftA2 (,)) which is equal to h f g x = liftA2 (,) (f x) (g x)...

A list can model an arbitrary number of results. On the other hand, Maybe models exactly one result or no result at all. Think about the following functions: f1 :: A -> [B] f2 :: B -> [C] f3 :: C -> [D] f4 :: D -> [E] It's not...

scala,clojure,monads,continuations,maybe

"In terms of" is a loose phrase. The Result monad you've shown is more general than the Maybe monad; indeed I'd say that Maybe is a special case of Result. And in turn continuation is more general still, and Result can be seen as a special case of continuation -...

You can use MaybeT and the MonadPlus instance to use msum: f :: MaybeT IO Int f = msum [readInt, readInt, readInt] ...

The Maybe a is the standart "type with empty value". The way to extract that a is to perform a case-split or (better) use a fromMaybe :: a -> Maybe a -> a -- Defined in ‘Data.Maybe’ function, which is declared as fromMaybe :: a -> Maybe a -> a...

haskell,monads,monad-transformers,state-monad,maybe

The type I would recommend using is: StateT [Int] Maybe Int A really simple way to use Maybe/MaybeT is to just call mzero whenever you want to fail and mplus whenever you want to recover from a failed computation. This works even if they are layered within other monad transformers....

Yes you are right. The 3 functions func1, func2, func3 do the same thing. func2 has one extra step which is unnecessary. func1 uses do notation to express exactly the same computation as func3. However the a, b and c of func1 and func2 are not the same.

The type of id is c -> c (using a different letter so not to conflict with a and b that occur in the type of >>=). We can unify c -> c with a -> Maybe b if we pick c = a = Maybe b. So this means...

haskell,monads,monad-transformers,maybe

In short: Replace lift by the MaybeT constructor. Note that newtype MaybeT m a = MaybeT { runMaybeT :: m (Maybe a) } and lift :: (MonadTrans t, Monad m) => m a -> t m a Your use of lift in x <- lift lol is at the type...

function,haskell,tuples,data-type-conversion,maybe

You could also use Bitraversable: bitraverse id pure :: (Bitraversable t, Applicative f) => t (f c) d -> f (t c d) which specializes to bitraverse id pure :: (Maybe a, b) -> Maybe (a, b) ...

scala,scalaz,for-comprehension,maybe,higher-kinded-types

It seems likely that monad transformers can help you here. For example, the following compiles and I think does roughly what you want: import scalaz._, Scalaz._ abstract class Calculator[M[_]: Monad] { def divideBy(x: Float): M[Option[Float]] def multiplyBy(x: Float): M[Float] } class Test[M[_]: Monad](calc: Calculator[M]) { def doSomething(x: Float): OptionT[M, Float]...

exception,error-handling,clojure,maybe,either

Clojure error handling is generally JVM exception (unchecked) oriented. Slingshot makes using exceptions more pleasant by allowing, for example, destructuring on thrown exception values. For an alternative that allows erlang-style error handling you should look at dire. This blog post gives a good overview of the rational for dire as...

Pretty standard stuff. Just write a type-checker, and only evaluate the term when it typechecks. evalMay does this. You can of course enrich the set of constants and base types; I just used one of each for simplicity. import Control.Applicative ((<$), (<$>)) import Control.Monad (guard) import Safe (atMay) data Type...

haskell,random,monad-transformers,maybe

Problem 1 Can't reproduce. There are already these instances for RandT. Problem 2 lookup returns Maybe, but you have a stack based on MaybeT. The reason why there is no MonadMaybe is that the corresponding type class is MonadPlus (or more general Alternative) - pure/return correspond to Just and empty/mzero...

You have to understand how fromMaybe works, first. Quoting the documentation, The fromMaybe function takes a default value and and Maybe value. If the Maybe is Nothing, it returns the default values; otherwise, it returns the value contained in the Maybe. So, you need to pass two values to fromMaybe,...

haskell,show,maybe,either,deriving

The instance for Maybe is defined explicitly in GHC.Show, along with instances for a whole bunch of other common types like tuples. You can find out where an instance was defined using the :i command in ghci: Prelude> :i Maybe data Maybe a = Nothing | Just a -- Defined...

c#,functional-programming,maybe

the answer to your comment/question is: you don't - yeah you could try it using recursive calls but this might fail horrible in C# and you are way better of with the while from x in X is just the monadic - bind (it get's translated into the SelectMany functions)...