[Haskell-cafe] Section Syntax Errors
ndmitchell at gmail.com
Sat Nov 11 14:57:13 EST 2006
Trying some things in Hugs:
Hugs> :t (+1)
flip (+) 1 :: Num a => a -> a
Hugs> :t (<0)
flip (<) 0 :: (Num a, Ord a) => a -> Bool
Hugs> :t (-1)
-1 :: Num a => a
If you see, Haskell interprets the first two as sections, but the last
one is treated as a unary minus, inside brackets - i.e. as though you
typed the numeric literal -1.
Haskell's treatment of negative literals is sometimes confusing...
On 11/11/06, Aditya Siram <aditya_siram at hotmail.com> wrote:
> Hi all,
> I am learning about sections and currying from SOE. There are three
> functions below. The first is from SOE and the other two are my own practice
> functions. Why does the third function fail?
> --Test for negative numbers (from SOE pg 109). This works
> posInts :: [Integer] -> [Bool]
> posInts = map (> 0)
> --Add 1 to a list of numbers. This works.
> addOne :: [Integer] -> [Integer]
> addOne = map (+ 1)
> --Subtract 1 from a list of numbers. This does NOT work.
> --Fails in Hugs with:
> -- Instance of Num (Integer -> Integer) required for definition of
> -- I tried : subOne :: Num a => [a] -> [a]
> -- and : subOne :: [Float] -> [Float]
> --in case the problem is with negative numbers. They both fail.
> --Without any type signature I get:
> -- Unresolved top level overloading
> subOne :: [Integer] -> [Integer]
> subOne = map (- 1)
> Add a Yahoo! contact to Windows Live Messenger for a chance to win a free
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe