Does this typeclass have a name?

Hi all, I was wondering if anyone out there knows if this type class has a name? class Foo a e where foo :: e -> a -> a bar :: a (I also have a fundep a -> e, but that's not essential.) Essentially the usage is: You have a sequence of "events" e_i and a starting value "bar" and can use the "foo" function to apply all events to that starting value foo e_n $ foo e_{n-1} $ ... $ foo e_0 $ bar and thus get the final value of the a induced by the events e_i. (I've included the "bar" starting value in the type class, but I suppose it could be supplied by a Default instance.) Regards,

On 21 April 2014 15:09, Bardur Arantsson
Hi all,
I was wondering if anyone out there knows if this type class has a name?
class Foo a e where foo :: e -> a -> a bar :: a
(I also have a fundep a -> e, but that's not essential.)
Essentially the usage is:
You have a sequence of "events" e_i and a starting value "bar" and can use the "foo" function to apply all events to that starting value
foo e_n $ foo e_{n-1} $ ... $ foo e_0 $ bar
= foldr foo bar [e_n, e_{n-1} .. e_0] ?
and thus get the final value of the a induced by the events e_i.
(I've included the "bar" starting value in the type class, but I suppose it could be supplied by a Default instance.)
Regards,
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com http://IvanMiljenovic.wordpress.com

On 2014-04-21 09:04, Ivan Lazar Miljenovic wrote:
On 21 April 2014 15:09, Bardur Arantsson
wrote: Hi all,
I was wondering if anyone out there knows if this type class has a name?
class Foo a e where foo :: e -> a -> a bar :: a
(I also have a fundep a -> e, but that's not essential.)
Essentially the usage is:
You have a sequence of "events" e_i and a starting value "bar" and can use the "foo" function to apply all events to that starting value
foo e_n $ foo e_{n-1} $ ... $ foo e_0 $ bar
= foldr foo bar [e_n, e_{n-1} .. e_0] ?
Yes, indeed, but I want the type class to constrain things since there are other interacting constraints on the types "a" and "e" (plus there's the fundep that I mentioned). The "single instance" part of type classes is also very desirable. Regards,

On 21 April 2014 18:08, Bardur Arantsson
On 2014-04-21 09:04, Ivan Lazar Miljenovic wrote:
On 21 April 2014 15:09, Bardur Arantsson
wrote: Hi all,
I was wondering if anyone out there knows if this type class has a name?
class Foo a e where foo :: e -> a -> a bar :: a
(I also have a fundep a -> e, but that's not essential.)
Essentially the usage is:
You have a sequence of "events" e_i and a starting value "bar" and can use the "foo" function to apply all events to that starting value
foo e_n $ foo e_{n-1} $ ... $ foo e_0 $ bar
= foldr foo bar [e_n, e_{n-1} .. e_0] ?
Yes, indeed, but I want the type class to constrain things since there are other interacting constraints on the types "a" and "e" (plus there's the fundep that I mentioned). The "single instance" part of type classes is also very desirable.
Typeclasses only really make sense if you're defining polymorphic functions that deal with a variety of these kinds of types. If that's the case, define your own typeclass (as it doesn't appear generic enough to be found in existing libraries) and define the instances you need. Otherwise, maybe just define an explicit dictionary record with values for every possible type pairing (and use an associated type instance if you want to explicitly state that there's a relation between a and e)? -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com http://IvanMiljenovic.wordpress.com

On 2014-04-21 11:25, Ivan Lazar Miljenovic wrote:
On 21 April 2014 18:08, Bardur Arantsson
wrote: On 2014-04-21 09:04, Ivan Lazar Miljenovic wrote:
On 21 April 2014 15:09, Bardur Arantsson
wrote: Hi all,
I was wondering if anyone out there knows if this type class has a name?
class Foo a e where foo :: e -> a -> a bar :: a
(I also have a fundep a -> e, but that's not essential.)
Essentially the usage is:
You have a sequence of "events" e_i and a starting value "bar" and can use the "foo" function to apply all events to that starting value
foo e_n $ foo e_{n-1} $ ... $ foo e_0 $ bar
= foldr foo bar [e_n, e_{n-1} .. e_0] ?
Yes, indeed, but I want the type class to constrain things since there are other interacting constraints on the types "a" and "e" (plus there's the fundep that I mentioned). The "single instance" part of type classes is also very desirable.
Typeclasses only really make sense if you're defining polymorphic functions that deal with a variety of these kinds of types.
If that's the case, define your own typeclass (as it doesn't appear generic enough to be found in existing libraries) and define the instances you need.
Of course, I'm already doing exactly that -- I really was just wondering if there might be a name for the type class :). Regards,

On Mon, Apr 21, 2014 at 07:09:13AM +0200, Bardur Arantsson wrote:
class Foo a e where foo :: e -> a -> a bar :: a [...] You have a sequence of "events" e_i and a starting value "bar" and can use the "foo" function to apply all events to that starting value
Do you *really* want a typeclass for this, rather than a value? Tom

Your class looks like Unfoldable from
Data.Collectionshttp://hackage.haskell.org/package/collections-api-1.0.0.0/docs/Data-Collect....
foo is insert and bar is empty. The other three methods can be defined in
terms of insert and empty.
On 21 April 2014 07:09, Bardur Arantsson
Hi all,
I was wondering if anyone out there knows if this type class has a name?
class Foo a e where foo :: e -> a -> a bar :: a
(I also have a fundep a -> e, but that's not essential.)
Essentially the usage is:
You have a sequence of "events" e_i and a starting value "bar" and can use the "foo" function to apply all events to that starting value
foo e_n $ foo e_{n-1} $ ... $ foo e_0 $ bar
and thus get the final value of the a induced by the events e_i.
(I've included the "bar" starting value in the type class, but I suppose it could be supplied by a Default instance.)
Regards,
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

I think what you're looking for are monoid actions:
http://hackage.haskell.org/package/monoid-extras-0.2.2.0/docs/Data-Monoid-Ac...
And the laws the typeclass should satisfy:
foo bar = id
foo f . foo g = foo (f `mappend` g)
The identity law is optional, in whihc case your 'e' would be a semigroup
without a default 'bar'
On 21 April 2014 11:46, Tobias Brandt
Your class looks like Unfoldable from Data.Collectionshttp://hackage.haskell.org/package/collections-api-1.0.0.0/docs/Data-Collect.... foo is insert and bar is empty. The other three methods can be defined in terms of insert and empty.
On 21 April 2014 07:09, Bardur Arantsson
wrote: Hi all,
I was wondering if anyone out there knows if this type class has a name?
class Foo a e where foo :: e -> a -> a bar :: a
(I also have a fundep a -> e, but that's not essential.)
Essentially the usage is:
You have a sequence of "events" e_i and a starting value "bar" and can use the "foo" function to apply all events to that starting value
foo e_n $ foo e_{n-1} $ ... $ foo e_0 $ bar
and thus get the final value of the a induced by the events e_i.
(I've included the "bar" starting value in the type class, but I suppose it could be supplied by a Default instance.)
Regards,
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Oh, and bar = mempty On 21 April 2014 15:46, Andras Slemmer <0slemi0@gmail.com> wrote:
I think what you're looking for are monoid actions: http://hackage.haskell.org/package/monoid-extras-0.2.2.0/docs/Data-Monoid-Ac... And the laws the typeclass should satisfy: foo bar = id foo f . foo g = foo (f `mappend` g)
The identity law is optional, in whihc case your 'e' would be a semigroup without a default 'bar'
On 21 April 2014 11:46, Tobias Brandt
wrote: Your class looks like Unfoldable from Data.Collectionshttp://hackage.haskell.org/package/collections-api-1.0.0.0/docs/Data-Collect.... foo is insert and bar is empty. The other three methods can be defined in terms of insert and empty.
On 21 April 2014 07:09, Bardur Arantsson
wrote: Hi all,
I was wondering if anyone out there knows if this type class has a name?
class Foo a e where foo :: e -> a -> a bar :: a
(I also have a fundep a -> e, but that's not essential.)
Essentially the usage is:
You have a sequence of "events" e_i and a starting value "bar" and can use the "foo" function to apply all events to that starting value
foo e_n $ foo e_{n-1} $ ... $ foo e_0 $ bar
and thus get the final value of the a induced by the events e_i.
(I've included the "bar" starting value in the type class, but I suppose it could be supplied by a Default instance.)
Regards,
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On 2014-04-21 15:46, Andras Slemmer wrote:
I think what you're looking for are monoid actions: http://hackage.haskell.org/package/monoid-extras-0.2.2.0/docs/Data-Monoid-Ac... And the laws the typeclass should satisfy: foo bar = id foo f . foo g = foo (f `mappend` g)
The identity law is optional, in whihc case your 'e' would be a semigroup without a default 'bar'
Ah, yes, thanks. That looks about right, but unfortunately I have even less structure in that I don't have a monoid -- I had previously looked at group actions, but those have various extra laws. Maybe I should just call it "Action", but avoid the monoid bits. Thanks all,

Just for completeness another option: http://hackage.haskell.org/package/reducers-3.10.2/docs/Data-Semigroup-Reduc...
But this probably has the same problem, as it requires a Semigroup.
Sjoerd
On 21 Apr 2014, at 20:23, Bardur Arantsson
On 2014-04-21 15:46, Andras Slemmer wrote:
I think what you're looking for are monoid actions: http://hackage.haskell.org/package/monoid-extras-0.2.2.0/docs/Data-Monoid-Ac... And the laws the typeclass should satisfy: foo bar = id foo f . foo g = foo (f `mappend` g)
The identity law is optional, in whihc case your 'e' would be a semigroup without a default 'bar'
Ah, yes, thanks. That looks about right, but unfortunately I have even less structure in that I don't have a monoid -- I had previously looked at group actions, but those have various extra laws.
Maybe I should just call it "Action", but avoid the monoid bits.
Thanks all,
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (6)
-
Andras Slemmer
-
Bardur Arantsson
-
Ivan Lazar Miljenovic
-
Sjoerd Visscher
-
Tobias Brandt
-
Tom Ellis