Is there any standard implementation of the "trivial constraint", or "object class"?
Asked Answered
B

1

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)?

Bestialize answered 6/2, 2014 at 14:0 Comment(6)
What problem are you trying to solve with this?Darkish
@WW.: right now, type (-->) = ConstrainedCategory (->) Trivial. 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.Bestialize
I believe that () :: Constraint is the trivial constraint.Jehiah
@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 -> ().Bestialize
ah, sorry for not reading your question carefullyJehiah
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.Jehiah
B
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
Bestialize answered 30/5, 2014 at 10:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.