Skip to content

Make HsIf more polymorphic with RebindableSyntax

Currently, ifThenElse is typed this way:

ifThenElse :: pred_ty -> b_ty -> b_ty -> res_ty

I propose to change this to:

ifThenElse :: pred_ty -> b1_ty -> b2_ty -> res_ty

to support expressions like this:

ifThenElse :: Maybe a -> (a -> b) -> b -> b
ifThenElse (Just a) f _ = f a
ifThenElse Nothing  _ e = e

example :: String
example = if Just 2
             then \v -> show v
             else "No value"

The fix is very simple and just one more line to add to the typechecker. Patch is attached.

Trac metadata
Trac field Value
Version 7.0.1
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information