(no subject)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

(no subject)

Corentin Dupont
Hi guys,
is there some library with a Monad (+Applicative, Functor...) instance of the following type:

data Todo a b = Todo [a] | Done b

Thanks!
Corentin

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: Todo monad

Francesco Ariis
On Tue, Aug 16, 2016 at 08:21:31PM +0200, Corentin Dupont wrote:
> Hi guys,
> is there some library with a Monad (+Applicative, Functor...) instance of
> the following type:
>
> data Todo a b = Todo [a] | Done b

What is the general idea behind the "todo monad"? As an unrepented
procrastinator, I might learn something useful.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: (no subject)

David Kraeutmann
In reply to this post by Corentin Dupont
This looks functionally identical to type Todo a b = Either [a] b, and Either has a Monad instance.
On 8/16/2016 8:21 PM, Corentin Dupont wrote:

> Hi guys,
> is there some library with a Monad (+Applicative, Functor...) instance of
> the following type:
>
> data Todo a b = Todo [a] | Done b
>
> Thanks!
> Corentin
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
>


_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.

smime.p7s (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Todo monad

Mihai Maruseac
In reply to this post by Francesco Ariis
You could say that yak shaving is bind, you just get more stuff on the
"todo list".

On Tue, Aug 16, 2016 at 2:21 PM, Francesco Ariis <[hidden email]> wrote:

> On Tue, Aug 16, 2016 at 08:21:31PM +0200, Corentin Dupont wrote:
>> Hi guys,
>> is there some library with a Monad (+Applicative, Functor...) instance of
>> the following type:
>>
>> data Todo a b = Todo [a] | Done b
>
> What is the general idea behind the "todo monad"? As an unrepented
> procrastinator, I might learn something useful.
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.



--
Mihai Maruseac (MM)
"If you can't solve a problem, then there's an easier problem you can
solve: find it." -- George Polya
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: Todo monad

Jules Mazur
In reply to this post by Francesco Ariis
Honest question -- why use this over e.g. a callback function?

The point of this structure, as I understand it, would be to establish the status of asynchronous computations being performed from `[a]`; it follows that this status would be used to execute a follow-up computation.

Jules

On Aug 16 2016, at 2:27 pm, Francesco Ariis <[hidden email]> wrote:

On Tue, Aug 16, 2016 at 08:21:31PM +0200, Corentin Dupont wrote:
> Hi guys,
> is there some library with a Monad (+Applicative, Functor...) instance of
> the following type:
>
> data Todo a b = Todo [a] | Done b

What is the general idea behind the "todo monad"? As an unrepented
procrastinator, I might learn something useful.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.


_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: (no subject)

David Kraeutmann
In reply to this post by David Kraeutmann
I went from the assumption that he just wants something like

instance Monad (Todo a)

and that implies that b is the type inside of the monad.


On 08/16/2016 08:23 PM, David Kraeutmann wrote:

> This looks functionally identical to type Todo a b = Either [a] b, and Either has a Monad instance.
> On 8/16/2016 8:21 PM, Corentin Dupont wrote:
>> Hi guys,
>> is there some library with a Monad (+Applicative, Functor...) instance of
>> the following type:
>>
>> data Todo a b = Todo [a] | Done b
>>
>> Thanks!
>> Corentin
>>
>>
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> To (un)subscribe, modify options or view archives go to:
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>> Only members subscribed via the mailman list are allowed to post.
>>
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: (no subject)

David Kraeutmann
This was in reply to Theodore's message:

> I have a hunch that the desired behavior is Either b [a], tho. (Or
possibly [Either b a]?)


On 08/16/2016 11:12 PM, David Kraeutmann wrote:

> I went from the assumption that he just wants something like
>
> instance Monad (Todo a)
>
> and that implies that b is the type inside of the monad.
>
>
> On 08/16/2016 08:23 PM, David Kraeutmann wrote:
>> This looks functionally identical to type Todo a b = Either [a] b, and Either has a Monad instance.
>> On 8/16/2016 8:21 PM, Corentin Dupont wrote:
>>> Hi guys,
>>> is there some library with a Monad (+Applicative, Functor...) instance of
>>> the following type:
>>>
>>> data Todo a b = Todo [a] | Done b
>>>
>>> Thanks!
>>> Corentin
>>>
>>>
>>>
>>> _______________________________________________
>>> Haskell-Cafe mailing list
>>> To (un)subscribe, modify options or view archives go to:
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>>> Only members subscribed via the mailman list are allowed to post.
>>>
>>
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> To (un)subscribe, modify options or view archives go to:
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>> Only members subscribed via the mailman list are allowed to post.
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: (no subject)

Corentin Dupont
In reply to this post by David Kraeutmann
That, right, just to clarify, my instances are like that:

instance Applicative (Todo a) where
   pure                = Done
   Todo as <*> Todo bs = Todo $ as ++ bs
   Todo as <*> _       = Todo as
   Done f  <*> r       = fmap f r

instance Monad (Todo a) where
   return        = Done
   Todo as >>= _ = Todo as
   Done a >>= f  = f a 


It's basically accumulating on the Todos. Either [a] b does not fit because it does not accumulate on the a's.


On Tue, Aug 16, 2016 at 11:12 PM, David Kraeutmann <[hidden email]> wrote:
I went from the assumption that he just wants something like

instance Monad (Todo a)

and that implies that b is the type inside of the monad.


On 08/16/2016 08:23 PM, David Kraeutmann wrote:
> This looks functionally identical to type Todo a b = Either [a] b, and Either has a Monad instance.
> On 8/16/2016 8:21 PM, Corentin Dupont wrote:
>> Hi guys,
>> is there some library with a Monad (+Applicative, Functor...) instance of
>> the following type:
>>
>> data Todo a b = Todo [a] | Done b
>>
>> Thanks!
>> Corentin
>>
>>
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> To (un)subscribe, modify options or view archives go to:
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>> Only members subscribed via the mailman list are allowed to post.
>>
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.


_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: (no subject)

Chris Wong-2

Hi Corentin,

That's called the "Validation applicative". I'm on my phone so I can't link, but that phrase should give you a starting point.

Note that your type actually has no valid Monad instance that is consistent with the Applicative. That's because while the Applicative accumulates data, the Monad throws it away every time.

Chris


On Aug 17, 2016 09:56, "Corentin Dupont" <[hidden email]> wrote:
That, right, just to clarify, my instances are like that:

instance Applicative (Todo a) where
   pure                = Done
   Todo as <*> Todo bs = Todo $ as ++ bs
   Todo as <*> _       = Todo as
   Done f  <*> r       = fmap f r

instance Monad (Todo a) where
   return        = Done
   Todo as >>= _ = Todo as
   Done a >>= f  = f a 


It's basically accumulating on the Todos. Either [a] b does not fit because it does not accumulate on the a's.


On Tue, Aug 16, 2016 at 11:12 PM, David Kraeutmann <[hidden email]> wrote:
I went from the assumption that he just wants something like

instance Monad (Todo a)

and that implies that b is the type inside of the monad.


On 08/16/2016 08:23 PM, David Kraeutmann wrote:
> This looks functionally identical to type Todo a b = Either [a] b, and Either has a Monad instance.
> On 8/16/2016 8:21 PM, Corentin Dupont wrote:
>> Hi guys,
>> is there some library with a Monad (+Applicative, Functor...) instance of
>> the following type:
>>
>> data Todo a b = Todo [a] | Done b
>>
>> Thanks!
>> Corentin
>>
>>
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> To (un)subscribe, modify options or view archives go to:
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>> Only members subscribed via the mailman list are allowed to post.
>>
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.


_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: (no subject)

David Feuer
In reply to this post by Corentin Dupont

Your Monad instance does not correspond to your Applicative instance as required by the class laws. Your Monad instance never appends the way the Applicative one does. And there's no way to make it do so. I don't think you've defined your type the way you really want. But without many details about how you wish to use it, it's hard to say how to fix the problem.


On Aug 16, 2016 5:56 PM, "Corentin Dupont" <[hidden email]> wrote:
That, right, just to clarify, my instances are like that:

instance Applicative (Todo a) where
   pure                = Done
   Todo as <*> Todo bs = Todo $ as ++ bs
   Todo as <*> _       = Todo as
   Done f  <*> r       = fmap f r

instance Monad (Todo a) where
   return        = Done
   Todo as >>= _ = Todo as
   Done a >>= f  = f a 


It's basically accumulating on the Todos. Either [a] b does not fit because it does not accumulate on the a's.


On Tue, Aug 16, 2016 at 11:12 PM, David Kraeutmann <[hidden email]> wrote:
I went from the assumption that he just wants something like

instance Monad (Todo a)

and that implies that b is the type inside of the monad.


On 08/16/2016 08:23 PM, David Kraeutmann wrote:
> This looks functionally identical to type Todo a b = Either [a] b, and Either has a Monad instance.
> On 8/16/2016 8:21 PM, Corentin Dupont wrote:
>> Hi guys,
>> is there some library with a Monad (+Applicative, Functor...) instance of
>> the following type:
>>
>> data Todo a b = Todo [a] | Done b
>>
>> Thanks!
>> Corentin
>>
>>
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> To (un)subscribe, modify options or view archives go to:
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>> Only members subscribed via the mailman list are allowed to post.
>>
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.


_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: Todo monad

Carl Eyeinsky
In reply to this post by Francesco Ariis

For sure you need to be able to add stuff to the todo list ;)


On Aug 16, 2016 8:27 PM, "Francesco Ariis" <[hidden email]> wrote:
On Tue, Aug 16, 2016 at 08:21:31PM +0200, Corentin Dupont wrote:
> Hi guys,
> is there some library with a Monad (+Applicative, Functor...) instance of
> the following type:
>
> data Todo a b = Todo [a] | Done b

What is the general idea behind the "todo monad"? As an unrepented
procrastinator, I might learn something useful.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.