Re: failure w/ simple example

Olaf Chitil <[email protected]>
Newsgroups gmane.comp.lang.haskell.hat
Organization Department of Computer Science, The University of York
Message-ID <[email protected]>
> I have the following simple program for which Hat does not seem to
> produce compilable code.

> main = putStr (show $ 4 ^ 2)

> Any suggestions?

Yes. You came across a restriction of Hat which, as I just notice, is
unfortunately not documented.

This example needs type defaulting to work. You can see in Hugs

Prelude> :t putStr (show $ 4 ^ 2)
putStr (show $ 4 ^ 2) :: (Integral a, Num b) => IO ()

"a" and "b" are the types of "4" and "2", and the defaulting mechanism
of Haskell sets them to "Integer".

In the Hat-transformed code defaulting does not apply, because the
transformed code uses different classes "Integeral", "Num" etc, but by
definition defaulting only applies to a set number of standard numeric
classes.

The simple solution is to add type annotations:

main = putStr (show $ (4::Integer) ^ (2::Integer))

Don't worry, in practice this situation occures very rarely. (Only twice
in the Haskell standard libraries.) However, an "ambiguous type
variable" error message is a clear indicator of this problem. To locate
in your module where you have to place a type annotation, just add
"default ()" to the module and compile it normally.

Olaf

-- 
OLAF CHITIL, 
 Dept. of Computer Science, The University of York, York YO10 5DD, UK. 
 URL: http://www.cs.york.ac.uk/~olaf/
 Tel: +44 1904 434756; Fax: +44 1904 432767
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.