Opened 12 years ago

Closed 12 years ago

Last modified 44 years ago

#67 closed bug (Wont Fix)

Signature context in recursive groups

Reported by: nobody Owned by: nobody
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 5.0
Keywords: Cc:
Operating System: Architecture:
Type of failure: Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

Hello,

I have a problem with signature contexts in mutually
recursive groups. I want to write a scanner, which is
able to read inputs of the form "int(3)" or
"float(2,0)" and return corresponding values of the
datatype:

data Token = TInt Int
	   | TFloat Float
   deriving (Read,Show)

Both constructors have the same type. Therefore, I want
to pass them to another function, which reads the
corresponding number with the function reads:

scan :: String -> [Token]
scan ('i':'n':'t':str) = scanNumber TInt str
scan ('f':'l':'o':'a':'t':str) = scanNumber TInt str

scanNumber :: Read a => (a -> Token) -> String ->
[Token]
scanNumber tokenCons ('(':str) = case reads str of
		                   ((n,(')':str1)):_) -> tokenCons
                                                                           
n:scan str1
		                   _            -> error "no literal"

main = print (scan "int(4)")

In Hugs this program works fine, but ghc does not
accept it, because of a mutually recursive group. Is
this a feature or a bug?
What does the Haskell 98 standard say?

Thanks and regards,

Frank Huch

Change History (1)

comment:1 Changed 12 years ago by simonmar

  • Status changed from assigned to closed
Logged In: YES 
user_id=48280

Apparently this behaviour is mandated by Haskell 98, see:

  http://www.haskell.org/pipermail/glasgow-haskell-
bugs/2001-December/002069.html

You can avoid the problem in your case by explicitly 
passing 'reads' from scan to scanNumber, thus avoiding the 
context on scanNumber.
Note: See TracTickets for help on using tickets.