Typeclass constraints and functional dependencies - some questions or maybe a bug?

53 views
Skip to first unread message

Max Kaye

unread,
Dec 14, 2017, 12:56:57 AM12/14/17
to purescript
Hello,

I'm experimenting with typeclass constraints and found something I think should work that doesn't. I suspect I'm misunderstanding things, so I'd be grateful for any help :)

Here's a small example:

```
class C1 a b | a -> b
class C1 a b <= C2 a b | a -> b where
     f :: a
```

This compiles, but the `a -> b` dependency is repeated. If I remove the second instance of it:

```
class C1 a b | a -> b
class C1 a b <= C2 a b where
    f :: a
```

then I get a compile error saying :
  The declaration f is unusable.
  This happens when a constraint couldn't possibly have enough information to work out which instance is required.

But surely, if C2 is constrained by C1, and C1 has the fundep `a -> b`, then `f` of C2 should sort of inherit that, right?
I'm not sure if I'm making a conceptual error here, or if the PureScript compiler isn't inferring something that it could.

Functional dependency is new to me, so any additional reading you could point me to would be appreciated too. As an aside on this point, I think `a -> b` as a fundep means "type a implies type b" or "type b is determined by type a", but not 100% on this.

Cheers
Max

PS. First time posting here, apologies if there are posting guidelines I'm not adhering to. Let me know if this is the case.

Nathan Faubion

unread,
Dec 16, 2017, 2:50:23 PM12/16/17
to purescript
What you want to do is reasonable, but not currently supported. https://github.com/purescript/purescript/issues/2397
Reply all
Reply to author
Forward
0 new messages