GHC does not infer type of `tagToEnum#` expression
Compiling this program:
{-# LANGUAGE MagicHash #-}
module TTE where
import GHC.Prim
f = case tagToEnum# 1# of
True -> "True"
False -> "False"
gives a compilation error:
[1 of 1] Compiling TTE ( tte.hs, tte.o )
tte.hs:6:10:
tagToEnum# must appear applied to one argument
In the expression: tagToEnum# 1#
In the expression:
case tagToEnum# 1# of {
True -> "True"
False -> "False" }
In an equation for ‛f’:
f = case tagToEnum# 1# of {
True -> "True"
False -> "False" }
To make it work one needs to supply type annotation for tagToEnum#
: case tagToEnum# 1# :: Bool of
. I would expect however that type will be inferred from type of patterns in the branches. Although I can imagine that things might get complicated for an ill-typed program:
f = case tagToEnum# 1# of
True -> "True"
3 -> "What now?"
If it is not possible to infer type of scrutinee based on patterns then I would expect to get more informative error message. Current one - tagToEnum# must appear applied to one argument
- is very misleading. When I saw it for the first time it took me about 15 minutes to actually figure out what GHC expects me to do.
Trac metadata
Trac field | Value |
---|---|
Version | 7.7 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |