[Haskell-cafe] asserting the type of a binding in a "do"
expression
Henning Thielemann
lemming at henning-thielemann.de
Sat Apr 26 05:09:02 EDT 2008
On Sat, 26 Apr 2008, Ken Takusagawa wrote:
> This works (with -fglasgow-exts):
>
> foo::IO Int;
> foo = do{
> (x::Int) <- bar;
> return x;};
>
> bar = undefined
>
> But this does not:
>
> foo::IO a;
> foo = do{
> (x::a) <- bar;
> return x;};
>
> Error message: A pattern type signature cannot bind scoped type
> variables `a' unless the pattern has a rigid type context.
'asTypeOf' is the answer for Haskell98. You can also write your own helper
functions which might simplify that for your use cases.
More information about the Haskell-Cafe
mailing list