Skip to content
Snippets Groups Projects
Commit 04783b79 authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

[project @ 1999-04-29 12:21:50 by simonpj]

Document Olaf Chitils point about pattern matching against a polymoprhic argument
parent fa7bd36e
No related branches found
No related tags found
No related merge requests found
%
% $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 <tt>bind</tt> to extract the polymorphic bind and return functions
from the <tt>MonadT</tt> data structure, rather than using pattern
matching.
You cannot pattern-match against an argument that is polymorphic.
For example:
<tscreen><verb>
newtype TIM s a = TIM (ST s (Maybe a))
runTIM :: (forall s. TIM s a) -> Maybe a
runTIM (TIM m) = runST m
</verb></tscreen>
Here the pattern-match fails, because you can't pattern-match against
an argument of type <tt>(forall s. TIM s a)</tt>. Instead you
must bind the variable and pattern match in the right hand side:
<tscreen><verb>
runTIM :: (forall s. TIM s a) -> Maybe a
runTIM tm = case tm of { TIM m -> runST m }
</verb></tscreen>
The <tt>tm</tt> on the right hand side is (invisibly) instantiated, like
any polymorphic value at its occurrence site, and now you can pattern-match
against it.
<sect2>The partial-application restriction
<p>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment