PreludeTour: Difference between revisions

From HaskellWiki
No edit summary
No edit summary
Line 2: Line 2:




=== abs ===
;'''abs''':
 
{| border="0" cellpadding="4"
{| border="0" cellpadding="4"
|-
|-
Line 24: Line 23:
|}
|}


=== all ===
;'''all''':
{| border="0" cellpadding="4"
{| border="0" cellpadding="4"
|-
|-

Revision as of 13:34, 26 October 2009

A Tour of the Haskell Prelude

abs
type: abs :: Num a => a -> a
description: returns the absolute value of a number.
definition:
abs x
  | x >= 0 = x
  | otherwise = -x
usage:
Prelude> abs (-3)
3
all
type: all :: (a -> Bool) -> [a] -> Bool
description: pplied to a predicate and a list, returns True if all elements of the list satisfy the predicate, and False otherwise. Similar to the function any.
definition:
all p xs = and (map p xs)
usage:
Prelude> all (<11) [1..10]
True
Prelude> all isDigit "123abc"
False