30

I want just

class Trivial t
instance Trivial t

This is of course useless in Haskell 98 since you can just omit the constraint; but with ConstraintKinds we can have explicitly required arguments of kind * -> Constraint. Ideally, I would like to just define this as an "anonymous type-level function" \type a -> (), but that's evidently not possible.

What should I do, use something predefined or just define that class locally right where I need it (as nobody will need to access it because the instance is universal, that seems quite ok as well)?

duffymo
  • 305,152
  • 44
  • 369
  • 561
leftaroundabout
  • 117,950
  • 5
  • 174
  • 319
  • 1
    What problem are you trying to solve with this? – WW. Feb 06 '14 at 23:25
  • 1
    @WW.: right now, [`type (-->) = ConstrainedCategory (->) Trivial`](https://github.com/leftaroundabout/constrained-categories/blob/f2f06b52d0e8cf18cd84d4d9bd0c50247109652d/examples/Invertible.hs#L35). There, it is basically just needed to avoid a conflicting MPTC-FunDep of the non-endo–functor instance of the optionally-invertible function type, but I intend to make more general use of it. – leftaroundabout Feb 07 '14 at 00:48
  • 1
    I believe that `() :: Constraint` is the trivial constraint. – Joachim Breitner Feb 07 '14 at 11:22
  • 1
    @JoachimBreitner: sure that's the trivial `Constraint`, but _type constraints_ are in fact of kind `* -> Constraint`. Which can't be defined quite as easily as `(\_ -> ()) :: a -> ()`. – leftaroundabout Feb 07 '14 at 11:25
  • ah, sorry for not reading your question carefully – Joachim Breitner Feb 07 '14 at 11:26
  • In that case, I’d say: There are no type level lambdas, and I don’t find anything suitable in the libraries, so you will have to define it yourself. – Joachim Breitner Feb 07 '14 at 11:28

1 Answers1

2

As this appears to be quite popular, I finally pushed such a trivial-constraint class to a Hackage package.

import Data.Constraint.Trivial

id' :: Unconstrained t => t -> t
id' = id
leftaroundabout
  • 117,950
  • 5
  • 174
  • 319