tfwh-0.3.7.0

TFwH.Chap02.ExD

Description

Synopsis

# Documentation

>>> isSquare n = (n ==) $(^2)$ round $sqrt$ fromIntegral n
>>> nums :: [Int]; nums = [2..1000000]
>>> nums == nums
True


first :: (a -> Bool) -> [a] -> a Source #

Susan版 first は

first :: (a -> Bool) -> [a] -> a
first p = head . filter p


Beaver版 first は

first :: (a -> Bool) -> [a] -> a
first p xs | null xs   = error "Empty list"
| p x       = x
| otherwise = firstB p (tail xs)
where

>>> let firstS p = head . filter p  -- Susan版
>>> first isSquare nums == firstS isSquare nums
True


first' :: (b -> Bool) -> (a -> b) -> [a] -> b Source #

Susan の first' :: (b -> Bool) -> (a -> b) -> [a] -> b

first' :: (b -> Bool) -> (a -> b) -> [a] -> b
first' p f = head . filter p . map f


Beaver の first'

first'  :: (b -> Bool) -> (a -> b) -> [a] -> b
first' p f xs | null xs = error "Empty list"
| p x     = x
| otherwise = first' p f (tail xs)
where

>>> let first'S p f = head . filter p . map f
>>> first' isSquare (subtract 1 . (2*)) nums == first'S isSquare (subtract 1 . (2*)) nums
True