[Haskell-cafe] Does this typeclass have a name?

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Mon Apr 21 09:25:41 UTC 2014


On 21 April 2014 18:08, Bardur Arantsson <spam at scientician.net> wrote:
> On 2014-04-21 09:04, Ivan Lazar Miljenovic wrote:
>> On 21 April 2014 15:09, Bardur Arantsson <spam at scientician.net> 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 at gmail.com
http://IvanMiljenovic.wordpress.com


More information about the Haskell-Cafe mailing list