I don’t understand whether an ImplictParam
can be bound by a lambda (I can’t make it work) and if not, why not. Here’s an attempt, and the failure message. The User’s Guide suggests (by omission) that it’s not possible, but I don’t understand why it’s not possible. Is there some technical restriction?
{-# LANGUAGE ImplicitParams #-}
implicitDouble :: (?imp :: Int) => Int
implicitDouble = 2 * ?imp
double :: Int -> Int
double exp = let ?imp = exp in implicitDouble
-- ghci> double 5
-- 10
doubleLambda :: Int -> Int
doubleLambda (?imp) = implicitDouble
-- test26.hs:12:15: error: Expression syntax in pattern: ?imp
-- |
-- 12 | doubleLambda (?imp) = implicitDouble
-- | ^^^^
A group of implicit-parameter bindings may occur anywhere a normal group of Haskell bindings can occur, except at top level. That is, they can occur in a
let
(including in a list comprehension, or do-notation, or pattern guards), or awhere
clause. Note the following points:
https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/implicit_parameters.html