Direct use of if-then-else with function type cause "Program error"

Mike Gunter <[email protected]>
Newsgroups gmane.comp.lang.haskell.hugs.bugs
Message-ID <[email protected]>
With the following code

> run f = f 7 (-3)

> programError wd initVal = (if initVal < 0 then showAsUnsiged else const show) wd initVal
> noProblem wd initVal	  = f wd initVal  where f = if initVal < 0 then showAsUnsiged else const show

> showAsUnsiged width nIn	= show n  where n | nIn < 0	= 2^width + nIn
>                                                 | otherwise	= nIn

I get:

    $ hugs HugsIfFuncBug.lhs 
    __   __ __  __  ____   ___      _________________________________________
    ||   || ||  || ||  || ||__      Hugs 98: Based on the Haskell 98 standard
    ||___|| ||__|| ||__||  __||     Copyright (c) 1994-2002
    ||---||         ___||           World Wide Web: http://haskell.org/hugs
    ||   ||                         Report bugs to: [email protected]
    ||   || Version: November 2002  _________________________________________
    
    Haskell 98 mode: Restart with command line option -98 to enable extensions
    
    Reading file "/usr/lib/hugs/libraries/Hugs/Prelude.hs":
    Reading file "/usr/lib/hugs/libraries/Prelude.hs":
    Reading file "HugsIfFuncBug.lhs":
                       
    Hugs session for:
    /usr/lib/hugs/libraries/Hugs/Prelude.hs
    /usr/lib/hugs/libraries/Prelude.hs
    HugsIfFuncBug.lhs
    Type :? for help
    Main> run noProblem
    "125"
    Main> run programError
    "
    Program error: {instShow_v14_v1224 (showAsUnsiged instIntegral_v34 instOrd_v27 instNum_v30 (Num_fromInt (Real__sc0_Real (Integral__sc0_Integral instIntegral_v34)) 7))}
    
    Main> :q
    [Leaving Hugs]

Thanks.

        mike
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.