[Haskell-cafe] Expressing disjunctions of constraints
aquagnu at gmail.com
Tue Jul 24 05:17:35 UTC 2018
> I'd like to express that at least one of the parameters a and b is c
Hello, Olaf! I never do it, but as idea: may be to use type-level lists,
for example, and to add such condition in instance constraints? There is
package type-lists with types "functions" like Find, etc (for member
checking, appending, etc)...
23.07.2018 22:54, Olaf Klinke wrotes:
> Dear cafe,
> today I wrote a type class with three parameters.
> class Foo a b c | a b -> c where
> foo :: a -> b -> c
> instance Foo A R A where ...
> instance Foo R A A where ...
> In addition to the functional dependency I'd like to express that at least one of the parameters a and b is c, that is, Foo is the union of the two classes
> class Foo1 a b where
> foo1 :: a -> b -> a
> class Foo2 a b where
> foo2 :: a -> b -> b
> and furthermore the choice between Foo1 and Foo2 determines one parameter to be a fixed type, say R. I understand that logical disjunction poses problems for instance resolution  because adding an instance may affect the instance dictionary lookup. This should not happen in my case because in the end this would be a one-parameter type class. The ultimate aim is to use the same symbol for both a function
> foo :: R -> a -> a
> and for flip foo. Of course writing flip foo is not that much of a nuisance, I just wonder whether Haskell is expressive enough to do this.
>  https://stackoverflow.com/questions/10255148/how-can-i-combine-two-type-constraints-with-a-logical-or-in-haskell
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> Only members subscribed via the mailman list are allowed to post.
More information about the Haskell-Cafe