[GHC] #8318: GHC does not infer type of `tagToEnum#` expression

GHC ghc-devs at haskell.org
Tue Sep 17 17:50:26 CEST 2013


#8318: GHC does not infer type of `tagToEnum#` expression
----------------------------+----------------------------------------------
       Reporter:            |             Owner:
  jstolarek                 |            Status:  new
           Type:  bug       |         Milestone:
       Priority:  normal    |           Version:  7.7
      Component:  Compiler  |  Operating System:  Unknown/Multiple
       Keywords:            |   Type of failure:  GHC rejects valid program
   Architecture:            |         Test Case:
  Unknown/Multiple          |          Blocking:
     Difficulty:  Unknown   |
     Blocked By:            |
Related Tickets:            |
----------------------------+----------------------------------------------
 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.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8318>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler



More information about the ghc-tickets mailing list