Skip to content

RankNTypes don't work with PatternSynonyms

data PLambda a = Var a | Int Int | Bool Bool | If (PLambda a) (PLambda a) (PLambda a)
  | Add (PLambda a) (PLambda a) | Mult (PLambda a) (PLambda a)
  | Eq  (PLambda a) (PLambda a) | Lam (a -> PLambda a)
  | App (PLambda a) (PLambda a)

newtype Lam = L { un :: forall a. PLambda a }
llam :: (forall a. a -> PLambda a) -> Lam
llam f = L (Lam f)

works fine, but does not with pattern synonyms:

-- $ ghci -ignore-dot-ghci tirr.hs
-- GHCi, version 8.2.0.20170507: http://www.haskell.org/ghc/  :? for help
-- [1 of 1] Compiling Main             ( tirr.hs, interpreted )
-- 
-- tirr.hs:20:25: error:
--     • Couldn't match expected type ‘forall a. a -> PLambda a’
--                   with actual type ‘a0 -> PLambda a0’
--     • In the declaration for pattern synonym ‘LLam’
--     • Relevant bindings include
--         a :: a0 -> PLambda a0 (bound at tirr.hs:20:25)
--    |
-- 20 | pattern LLam a = L (Lam a)
--    |                         ^
-- Failed, modules loaded: none.
-- Prelude>

pattern LLam :: (forall a. a -> PLambda a) -> Lam
pattern LLam a = L (Lam a) 
Edited by Icelandjack
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information