I am learning Haskell by reading the book _The Haskell Road to Logic, Maths and Programming_ and by using Hugs98_plus_sep2006 which I have downloaded, built and installed on my AMD 64-bit OpenBSD system. The books says that Hugs will show the prompt 'Prelude>' initially until a script is loaded. The version of Hugs installed on my system shows initially the prompt 'Hugs>' and invoking several functions (primMinInt, primMaxInt, etc.) generate the error message to be undefined. Does Hugs still exhibit the behavior described in the book, or is there a problem with the newly ported Hugs on my system? /home/daf}hugs __ __ __ __ ____ ___ _________________________________________ || || || || || || ||__ Hugs 98: Based on the Haskell 98 standard ||___|| ||__|| ||__|| __|| Copyright (c) 1994-2005 ||---|| ___|| World Wide Web: http://haskell.org/hugs || || Bugs: http://hackage.haskell.org/trac/hugs || || Version: September 2006 _________________________________________ Haskell 98 mode: Restart with command line option -98 to enable extensions Type :? for help Hugs> primMinInt ERROR - Undefined variable "primMinInt" Hugs> primMaxInt ERROR - Undefined variable "primMaxInt" Hugs> :names *prim*Int Hugs.Prelude.primCharToInt Hugs.Prelude.primCmpInt Hugs.Prelude.primDivInt Hugs.Prelude.primEqInt Hugs.Prelude.primIntegerToInt Hugs.Prelude.primMaxInt Hugs.Prelude.primMinInt Hugs.Prelude.primMinusInt Hugs.Prelude.primModInt Hugs.Prelude.primMulInt Hugs.Prelude.primNegInt Hugs.Prelude.primPlusInt Hugs.Prelude.primPmInt Hugs.Prelude.primQrmInt Hugs.Prelude.primQuotInt Hugs.Prelude.primRemInt Hugs.Prelude.primShowsInt (17 names listed) Hugs> primCharToInt 'a' ERROR - Undefined variable "primCharToInt" Hugs> Thanks, Dave Feustel
I don't know the history behind changes of this nature, but it appears that these names are no longer directly exported. Instead, they are used by the system in the implementations of other functions which are visible. If you try typing :browse Hugs.Prelude at the Hugs> prompt, you will see that the names are not listed in those that are visible in this module. It seems like these names are mainly hooked in to support the implementation of type class functions (methods). For instance, since Int represents bounded integers, it is part of the type class Bounded. If you look in the list of names you get from browsing Hugs.Prelude, you will see that there are two names that look promising: minBound :: Bounded a => a -- class member maxBound :: Bounded a => a -- class member You can then use these to get the same results you would get from primMinInt and primMaxInt: Hugs> (minBound)::Int -2147483648 Hugs> (maxBound)::Int 2147483647 Similarly, with primCharToInt, Char is considered an Enum type, and there is a function named fromEnum. Hugs> fromEnum 'c' 99 Hugs> (toEnum 99)::Char 'c' I think in many cases you should be able to browse around the Prelude.hs file and figure out how to get access to the prim functions indirectly like this. For instance, the portions of the Prelude that correspond to the above are: primitive primMinInt, primMaxInt :: Int instance Bounded Int where minBound = primMinInt maxBound = primMaxInt primitive primCharToInt :: Char -> Int primitive primIntToChar :: Int -> Char instance Enum Char where toEnum = primIntToChar fromEnum = primCharToInt On my system at least, the Prelude.hs file with this information is in /usr/lib/hugs/packages/hugsbase/Hugs. I'm not sure where it would be on a Windows system, but I imagine there is a similar directory structure (maybe under Program Files\Hugs or some such). I hope this helps. Mark Dave@haskell.org wrote:
I am learning Haskell by reading the book _The Haskell Road to Logic, Maths and Programming_ and by using Hugs98_plus_sep2006 which I have downloaded, built and installed on my AMD 64-bit OpenBSD system. The books says that Hugs will show the prompt 'Prelude>' initially until a script is loaded. The version of Hugs installed on my system shows initially the prompt 'Hugs>' and invoking several functions (primMinInt, primMaxInt, etc.) generate the error message to be undefined. Does Hugs still exhibit the behavior described in the book, or is there a problem with the newly ported Hugs on my system?
/home/daf}hugs __ __ __ __ ____ ___ _________________________________________ || || || || || || ||__ Hugs 98: Based on the Haskell 98 standard ||___|| ||__|| ||__|| __|| Copyright (c) 1994-2005 ||---|| ___|| World Wide Web: http://haskell.org/hugs || || Bugs: http://hackage.haskell.org/trac/hugs || || Version: September 2006 _________________________________________
Haskell 98 mode: Restart with command line option -98 to enable extensions
Type :? for help Hugs> primMinInt ERROR - Undefined variable "primMinInt" Hugs> primMaxInt ERROR - Undefined variable "primMaxInt" Hugs> :names *prim*Int Hugs.Prelude.primCharToInt Hugs.Prelude.primCmpInt Hugs.Prelude.primDivInt Hugs.Prelude.primEqInt Hugs.Prelude.primIntegerToInt Hugs.Prelude.primMaxInt Hugs.Prelude.primMinInt Hugs.Prelude.primMinusInt Hugs.Prelude.primModInt Hugs.Prelude.primMulInt Hugs.Prelude.primNegInt Hugs.Prelude.primPlusInt Hugs.Prelude.primPmInt Hugs.Prelude.primQrmInt Hugs.Prelude.primQuotInt Hugs.Prelude.primRemInt Hugs.Prelude.primShowsInt (17 names listed) Hugs> primCharToInt 'a' ERROR - Undefined variable "primCharToInt" Hugs>
Thanks,
Dave Feustel _______________________________________________ Hugs-Users mailing list Hugs-Users@haskell.org http://www.haskell.org/mailman/listinfo/hugs-users
Hi
The books says that Hugs will show the prompt 'Prelude>' initially until a script is loaded. The version of Hugs installed on my system shows initially the prompt 'Hugs>'
Whether it says "Hugs" or "Prelude" isn't important, you can just ignore this. In Hugs> module the Prelude is in scope. As for the primitive operations, you shouldn't use them, ever. If you want to add two things use (+). They are merely an internal implementation detail, which I guess should never have been available to the user in the first place, and now isn't. I guess its a shame that a book that is only 2 years old is out of date, perhaps you might want to contact the authors to give them this information, so they can put it on a web page or something and save other people this confusion. Thanks Neil
On Sat, Dec 09, 2006 at 03:32:22PM +0000, Neil Mitchell wrote:
As for the primitive operations, you shouldn't use them, ever. If you want to add two things use (+). They are merely an internal implementation detail, which I guess should never have been available to the user in the first place, and now isn't. I guess its a shame that a book that is only 2 years old is out of date, perhaps you might want to contact the authors to give them this information, so they can put it on a web page or something and save other people this confusion.
Yes, these were internal details of the Hugs implementation of the Prelude, and shouldn't have been exposed. They were only ever visible when the Prelude was the current module, and have been properly hidden since the November 2002 release. But since they existed only to implement Haskell 98, there are always Haskell 98 alternatives, e.g. minBound::Int for primMinInt, as already mentioned.
Hello Dave, Saturday, December 9, 2006, 2:40:42 PM, you wrote:
(primMinInt, primMaxInt, etc.) generate the error message to be undefined. Does Hugs still exhibit the behavior described in the book, or is there a problem with the newly ported Hugs on my system?
there is "A Tour of the Haskell Prelude", i recommend you to look there. http://haskell.org/haskellwiki/Learning_Haskell -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
participants (5)
-
unknown@example.com -
Bulat Ziganshin -
Mark Hills -
Neil Mitchell -
Ross Paterson