3
class Foo (x :: * -> * -> *) where

data Bar a b

instance Foo Bar

type Baz a b = Either (Bar a b) b

instance Foo Baz -- does not work as Foo is a type synonym and not fully applied

For the given example is there a way to define an instance for Either (Bar a b) b without adding a newtype or altering Foo?

user1078763
  • 728
  • 5
  • 15
  • You can't, without a newtype or data wrapper. – chi Nov 29 '17 at 07:59
  • 1
    You normally aren’t allowed to define instances for type synonyms. Imagine you define a `Show` like class called `Write` (say) and you define an instance `Write Char` and `Write a => Write [a]` and now you want to do strings differently so you define `Write String`. But that isn’t allowed because `String` is just `[Char]` so Haskell wouldn’t be able to decide which instance to use. I think this is the root of your error even though your class has no members so all instances are isomorphic. There’s probably some extensions you can turn on to make this work – Dan Robertson Nov 29 '17 at 10:21
  • 2
    @DanRobertson [Nope](https://stackoverflow.com/q/22665556/1126841). Although I think `FlexibleInstances` is what would allow you to have both `Write String` and `Write a => Write [a]`; the `String` instance (since `String` is a fully applied type synonym) is used when applicable, otherwise the general list instance is used. – chepner Nov 29 '17 at 12:16
  • @chepner ah ok thanks for that – Dan Robertson Nov 29 '17 at 12:36

0 Answers0