haskellcompiler-errorsliterate-programming

literate haskell - Type error in application


Here is my code:

> newtype IN_0 = IN_0 Integer deriving Show

> nminus :: IN_0 -> IN_0 -> IN_0
> nminus (IN_0 z) (IN_0 z')
>        | z >= 0 && z' >= 0 = IN_0 $ maximum(0,z-z')
>        | otherwise = IN_0 0

When I compile this in ghci it compiles without error, but when I try to compile it in hugs I get this error message:

ERROR "untitled.lhs":51 - Type error in application
*** Expression     : maximum (0,z - z')
*** Term           : (0,z - z')
*** Type           : (b,Integer)
*** Does not match : [a]

Why ?


Solution

  • > newtype IN_0 = IN_0 Integer deriving Show
    
    > nminus :: IN_0 -> IN_0 -> IN_0
    > nminus (IN_0 z) (IN_0 z')
    >        | z >= 0 && z' >= 0 = IN_0 $ maximum [0,z-z']
    >        | otherwise = IN_0 0
    

    In Hugs you have to use [Square] brackets when using maximum