Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why the functional dependency in *Action classes? #170

Open
wolverian opened this issue May 9, 2023 · 3 comments
Open

Why the functional dependency in *Action classes? #170

wolverian opened this issue May 9, 2023 · 3 comments

Comments

@wolverian
Copy link

I'd like to be able to write a calculation (a *. b) *. c where a :: A, b :: B and c :: C.

I defined instances MultiplicativeAction A B and MultiplicativeAction A C. Now a *. b :: A and denote that with a', and a' *. c :: A, the types seem to match up. However, now I get the error Functional dependencies conflict between instance declarations (as they do).

There's surely a reason why the fundep is there, but I couldn't find the reason in the Haddocks, the code or the Git history. Could you open this up a bit?

@tonyday567
Copy link
Owner

The main reason for fundeps was to avoid TypeFamilies. There has, at least historically, been a reluctance to introduce type families to Prelude due to various performance issues that I think remain unresolved to date eg

https://gitlab.haskell.org/ghc/ghc/-/issues/8095
https://gitlab.haskell.org/ghc/ghc/-/issues/12088

Back in the day, numhask mirrored this conservatism in a naive attempt for a Num redesign to get taken seriously.

The typefam branch includes a switch to TypeFamilies for a MultiplicativeAction, by including a new type, Scalar eg

-- | Multiplicative Action
class
  (Multiplicative (Scalar m)) =>
  MultiplicativeAction m
  where
  type Scalar m :: Type

  infixl 7 .*
  (.*) :: Scalar m -> m -> m

(*.) = flip (.*)

Would this work for your use case?

I'll be releasing this soon as 0.11.

@wolverian
Copy link
Author

Thanks, I’ll try the branch!

@tonyday567
Copy link
Owner

I released 0.11 which goes with (|) rather than (.) etc. The dot was confusing some formatters and . is a way overused symbol in haskell. I hope it makes sense for your usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants