Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Monad  question (mike h)
   2. Re:  Monad question (יהושע ולך)
   3. Re:  Monad question (יהושע ולך)
   4. Re:  Monad question (יהושע ולך)
   5. Re:  Monad question (Imants Cekusins)


----------------------------------------------------------------------

Message: 1
Date: Thu, 25 Nov 2021 17:10:44 +0000
From: mike h <mike_k_hough...@yahoo.co.uk>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] Monad  question
Message-ID: <e09d997c-6180-4d98-ad29-3952d1e74...@yahoo.co.uk>
Content-Type: text/plain;       charset=utf-8

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

------------------------------

Message: 2
Date: Thu, 25 Nov 2021 19:46:05 +0200
From: יהושע ולך <yehoshu...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Monad question
Message-ID:
        <camcanrujd0j_hak1sj15qesjj56yncligefgfra038071+n...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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_hough...@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@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/1f2a6056/attachment-0001.html>

------------------------------

Message: 3
Date: Thu, 25 Nov 2021 19:53:41 +0200
From: יהושע ולך <yehoshu...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Monad question
Message-ID:
        <CAMcanRULZn9XAagNb31jCP=spxihvueqvaen11gbe9su1yb...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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 יהושע ולך <yehoshu...@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_hough...@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@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/26bed723/attachment-0001.html>

------------------------------

Message: 4
Date: Thu, 25 Nov 2021 19:54:21 +0200
From: יהושע ולך <yehoshu...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Monad question
Message-ID:
        <CAMcanRUU96B_RxKGTsZ-L8h=eymqiaxb8nrjrhbm__4zxlo...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

convert (Var mx) = mx >>= (return .Var)

Typo.

On Thu, Nov 25, 2021, 19:53 יהושע ולך <yehoshu...@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 יהושע ולך <yehoshu...@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_hough...@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@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-0001.html>

------------------------------

Message: 5
Date: Thu, 25 Nov 2021 20:36:02 +0200
From: Imants Cekusins <ima...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Monad question
Message-ID:
        <cap1qinyvqajb9bbpwmx69mi8ylxkrq2oek7a+gytczaxdoa...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Or you could derive Traversable for Expr

Then sequenceA can be used:

https://hoogle.haskell.org/?hoogle=f%20(m%20a)%20-%3E%20m%20(f%20a)

On Thu 25 Nov 2021, 19:54 יהושע ולך, <yehoshu...@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 יהושע ולך <yehoshu...@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_hough...@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@haskell.org
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>>
>> _______________________________________________
> Beginners mailing list
> Beginners@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/35d525ca/attachment.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 160, Issue 1
*****************************************

Reply via email to