[Haskell-beginners] Monad question
יהושע ולך
yehoshuapw at gmail.com
Thu Nov 25 17:54:21 UTC 2021
convert (Var mx) = mx >>= (return .Var)
Typo.
On Thu, Nov 25, 2021, 19:53 יהושע ולך <yehoshuapw at gmail.com> wrote:
> convert (Var mx) = mx >>= (return .Var x)
>
> Should also be the non-do-notation.
> (again, typing from a phone, and not tested)
>
> On Thu, Nov 25, 2021, 19:46 יהושע ולך <yehoshuapw at gmail.com> wrote:
>
>> I can't actually cheok right now,
>> but
>> ```
>> convert (Var mv) = do
>> v <- mv
>> return $ Var v
>> ```
>>
>> is the "do notation" which should work.
>> (and similarly for the other expression)
>>
>> On Thu, Nov 25, 2021, 19:13 mike h <mike_k_houghton at yahoo.co.uk> wrote:
>>
>>> Hi,
>>> This isn’t homework! I’ve been staring at this for several hours - and
>>> that usually works.
>>> I also tried typed holes to no avail. I thinks it is quite simple
>>> really but I’ve gone past seeing it!
>>>
>>> I have
>>> data Expr a = Var a | Add (Expr a) (Expr a)
>>>
>>> and would like to write
>>>
>>> convert :: Expr (Maybe a) -> Maybe (Expr a)
>>>
>>> which returns Nothing if there is an occurrence of Nothing inside the
>>> input expression e, otherwise it returns Just e', where e'
>>> is a new expression where the internal values of type a are not wrapped
>>> in Just.
>>> You should use the functionality of the Maybe monad to implement
>>> the convert function.
>>>
>>>
>>> Thanks
>>> Mike
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners at haskell.org
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20211125/c38b7d30/attachment.html>
More information about the Beginners
mailing list