How to reimplement the "all" function in Haskell? -
i need define functionall' :: ( -> bool ) -> [a] -> bool
verifies if elements list satisfy condition .
for example : all' ( <5) [1,2,3] = true
, all' (>=2) [1,1,2,2,3,3]
= false.
my main problem don't know how handle transmission of function.
functions in haskell passed other value. here's example progress:
dobothsatisfy :: (a -> bool) -> -> -> bool dobothsatisfy p x y = (p x) && (p y)
and usage:
dobothsatisfy (> 5) 6 7 == true dobothsatisfy (> 5) 1 8 == false
now try extend lists.
Comments
Post a Comment