|
|
Line 1: |
Line 1: |
− | == A Tour of the Haskell Prelude ==
| |
| | | |
− |
| |
− | ;<span id="abs">'''abs'''</span>:
| |
− | {| border="0" cellpadding="4"
| |
− | |-
| |
− | | ''type:'' || <hask>abs :: Num a => a -> a</hask>
| |
− | |-
| |
− | | ''description:'' || returns the absolute value of a number.
| |
− | |-
| |
− | | ''definition:''
| |
− | | <haskell>
| |
− | abs x
| |
− | | x >= 0 = x
| |
− | | otherwise = -x
| |
− | </haskell>
| |
− | |-
| |
− | | ''usage:''
| |
− | | <pre>
| |
− | Prelude> abs (-3)
| |
− | 3
| |
− | </pre>
| |
− | |}
| |
− |
| |
− | ;<span id="all">'''all'''</span>:
| |
− | {| border="0" cellpadding="4"
| |
− | |-
| |
− | | ''type:'' || <hask>all :: (a -> Bool) -> [a] -> Bool</hask>
| |
− | |-
| |
− | | ''description:'' || Applied 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:''
| |
− | | <haskell>
| |
− | all p xs = and (map p xs)
| |
− | </haskell>
| |
− | |-
| |
− | | ''usage:''
| |
− | | <pre>
| |
− | Prelude> all (<11) [1..10]
| |
− | True
| |
− | Prelude> all isDigit "123abc"
| |
− | False
| |
− | </pre>
| |
− | |}
| |