Function with Two Types?

Steinitz, Dominic J Dominic.J.Steinitz@BritishAirways.com
16 May 2001 18:25:22 Z


I wouldn't expect Hugs to give me two different types for the same function depending on what I'd typed in at the command line.

Dominic.

__   __ __  __  ____   ___      _________________________________________
||   || ||  || ||  || ||__      Hugs 98: Based on the Haskell 98 standard
||___|| ||__|| ||__||  __||     Copyright (c) 1994-1999
||---||         ___||           World Wide Web: http://haskell.org/hugs
||   ||                         Report bugs to: hugs-bugs@haskell.org
||   || Version: February 2000  _________________________________________

Hugs mode: Restart with command line option +98 for Haskell 98 mode

Reading file "C:\HUGS98\lib\Prelude.hs":
Reading file "C:\My Documents\functional\x690e\BEStc2.hs":

Hugs session for:
C:\HUGS98\lib\Prelude.hs
C:\My Documents\functional\x690e\BEStc2.hs
Type :? for help
Main> :t unBESNULL
unBESNULL :: BESable ([Char] -> Int) => BES -> NULL
Main> :t (Primitive' 5 NULL)
Primitive' 5 NULL :: BES
Main> :t unBESNULL
unBESNULL :: BES -> NULL
Main> unBESNULL (Primitive' 5 NULL)
ERROR: Unresolved overloading
*** Type       : BESable (Int -> NULL -> BES) => NULL
*** Expression : unBESNULL (Primitive' 5 NULL)

Main> :t unBESNULL
unBESNULL :: BESable (Int -> NULL -> BES) => BES -> NULL
Main> :t (Primitive' 5 NULL)
Primitive' 5 NULL :: BES
Main> :t unBESNULL
unBESNULL :: BES -> NULL


==============================

data NULL = NULL

data BES = forall a . (UnBESable a) =>
              Primitive' Int a |
              Constructed' Int [BES]

class BESable a where
   bes :: a -> BES
   unbes :: UnBESable b => a -> b

class UnBESable b where
   doNULL :: NULL -> b
   doInt  :: Int -> b  

instance BESable NULL where
   bes = Primitive' 5
   unbes = doNULL

instance UnBESable NULL where
   doNULL NULL = NULL
   doInt x     = error "Can't cast"

instance BESable Int where
   bes   = Primitive' 2
   unbes = doInt            

instance UnBESable Int where
   doNULL x = error "Can't cast"
   doInt x  = x 

unBESNULL (Primitive' 5 x) = (unbes x)::NULL

unBESInt (Primitive' 2 x) = (unbes x)::Int

-------------------------------------------------------------------------------------------------
21st century air travel     http://www.britishairways.com