in Haskell there is a default unit type, namely (). I'm looking for a polymorphic one (preferably in Hackage), for instance:
data PUT a = PUT
or perhaps a polymorphic zero type:
data PZT a = PZT (PZT a)
So yes, I could write one myself, by either of the above statements. I'm looking for one in hackage.
The reason I need it, is because I have a class with multiple type parameters, which contains a function that does not use one of them:
class MyClass a b where
someFunction :: a
-- and some other functions
when using this function "someFunction", GHC cannot find the right instance, so I changed my definition:
class MyClass a b where
someFunction :: (PUT b) -> a
Now when I call someFunction, I can use (PUT::SomeType) as its first argument, and Haskell can derive which instance I meant. Every time I use this trick, I write a new polymorphic unit type (it's just one line of codes), which gives me a bit of extra work when combining different libraries (because preferably, I'd use the same constructor everywhere). I'm sure that other people ran into this problem, so maybe one of them put a solution in hackage (ghc's packet manager)? I'd like to import it. Am I searching for the wrong thing, or does it not exist in hackage?
I think what you are looking for is usually called Proxy
. Since base-4.7, it is available in Data.Proxy
A similar thing, which is available in base since longer than Proxy
, is Const
, e.g. you can use Const ()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With