From: simonpj Date: Thu, 29 Apr 1999 12:21:50 +0000 (+0000) Subject: [project @ 1999-04-29 12:21:50 by simonpj] X-Git-Tag: Approximately_9120_patches~6275 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=04783b794ebe6f1b8edde5db931c46d9a0a2a46c;p=ghc-hetmet.git [project @ 1999-04-29 12:21:50 by simonpj] Document Olaf Chitils point about pattern matching against a polymoprhic argument --- diff --git a/ghc/docs/users_guide/glasgow_exts.vsgml b/ghc/docs/users_guide/glasgow_exts.vsgml index 9d0afcd..99eaf5d 100644 --- a/ghc/docs/users_guide/glasgow_exts.vsgml +++ b/ghc/docs/users_guide/glasgow_exts.vsgml @@ -1,5 +1,5 @@ % -% $Id: glasgow_exts.vsgml,v 1.8 1999/03/30 11:26:24 sof Exp $ +% $Id: glasgow_exts.vsgml,v 1.9 1999/04/29 12:21:50 simonpj Exp $ % % GHC Language Extensions. % @@ -1198,6 +1198,26 @@ and bind to extract the polymorphic bind and return functions from the MonadT data structure, rather than using pattern matching. +You cannot pattern-match against an argument that is polymorphic. +For example: + + newtype TIM s a = TIM (ST s (Maybe a)) + + runTIM :: (forall s. TIM s a) -> Maybe a + runTIM (TIM m) = runST m + + +Here the pattern-match fails, because you can't pattern-match against +an argument of type (forall s. TIM s a). Instead you +must bind the variable and pattern match in the right hand side: + + runTIM :: (forall s. TIM s a) -> Maybe a + runTIM tm = case tm of { TIM m -> runST m } + +The tm on the right hand side is (invisibly) instantiated, like +any polymorphic value at its occurrence site, and now you can pattern-match +against it. + The partial-application restriction