Home > front end >  Haskell: shortcut for type application
Haskell: shortcut for type application

Time:08-31

I have a call like someFunc @'SomeX @'SomeY .... Is there some aliasing syntax to make it shorter? Something like:

type ??? = @'SomeX @'SomeY

someFunc @??? ...

?

CodePudding user response:

Your example is very vague, but one thing you can do is to redefine someFunc with a more precise type:

someFunc :: a -> b -> a
someFunc x y = x

someFunc' :: Int -> Bool -> Int
someFunc' = someFunc

Then you can use someFunc' whenever you would previously write someFunc @Int @Bool.

Alternatively, if you only really care about that second @'SomeY argument, then you can use the snail: someFunc @_ @'SomeY. In this case the compiler will automatically try to fill in that underscore type application.

  • Related