
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,