But then, occasionally, in order to evaluate h I need a type application like:
f a b c d e = .... h @blike b e
where blike is some type that none of the other variables have.
Then I feel extreme sadness, as in order to do that I need to completely define the type of f:
f :: forall ... b. ( BLike b, ... )
occasionally, this is super annoying, because the type is really long.
it’d be so convenient if I could just somehow label the one type that I’d like to use as a type application, just like I can do for function arguments; i.e. can I curry these forall things?
Is there a way to do this?
[ edit: I’ve updated the original question since @jaror pointed out it was a bit wrong initially. ]
I share the same confusion with @jaror, but if all you want to do is to provide a partial type signature for f, you can take a look at the partial type signatures extension.
Can you give a complete example? I don’t understand why the @BLike type application
forces the type of f to be manually defined.
Sorry, I slightly messed up my example; to be more clear, what I would like to write is:
f a b c d e = .... h @blike b e
with:
f :: forall ... blike. ( BLike blike, ... )
then when I call f i’d do:
f @SomeBThing ...
I hope this is more clear. I’ll try and come up with some real code later this afternoon. (Edit: this example may be slightly overcomplicated, but I hope it indicates the essential idea; partially defining the type variables with forall, and then applying them.)
unfortunately in my case the blike class is not a type of anything I provide; i.e. it’s not a type of any of the arguments; it’s merely related; hence the need to pass it in as a type argument.
So it seems like you want to be able to write something like
f @blike a b c d e = ... h @blike b e
Yes exactly!
I think I’m familiar with the Proxy stuff; but in this case I don’t think adding Proxy really helps me; when doing the ugly undefined thing just works (horrible though it is.)
In this case you could use {-# LANGUAGE AllowAmbiguousTypes #-} and if you define
f ::
forall blike a b c d e.
a -> b -> c -> d -> e
f = ... h @blike b e
And then at the call-site: f @blike a b c d e will just work. (note that blike should be the first in the forall list so that it’s the first to be filled when using f @something)
I’ve heard of actual type arguments coming to GHC in the near(-ish) future, so that would also solve this for you.