Monday 15 August 2011

haskell - Returning True for only 1 Function out of the list of 3 -


Since I'm sure to use global variables in Haskell, I'm thinking that anyway I get the following Can i

  - There are elements in the list that are the odd list HasOdd :: [integer] - & gt; Bool - There are elements in the list that are even in the list of HASEven :: [integer] - & gt; Boole - The list has a length & gt; 5 long list :: [integer] - & gt; Boole - Function in Map [Bool] - This function can not be modified to fix the problem. Checklist :: [integer] - & gt; [Bool] checkList xs = map (\ y - & gt; y xs) listChecker where listChecker = [listHasOdd, listHasEven, longList]   

Anyway, I can make sure that in them Only a true return from?

For example, [1,2,3,5], I just want to return to the list which is true [true, false, false] (evaluation from top to bottom ).

Another example, [2,4,6,8,10,12,14], should be returned [false, true, false]

In other words, the checklist [1,2,3,5] returns [true, false, false], checklist [2,4,6,8,10,12,14] returns [false , True, false]

** The last task will always be wrong in my example, because it is not inaccessible

I know that I have an if statement I can do that to check that the last one is true but it seems like a very dumb idea. Or is this really the way to do it? (Recalling the results of "previous ceremony" while keeping Haskell in mind)

This is the best I can come together in It is relatively painless to handle the number of potential pockets of a poker hand, for example.

  Data Results = ListHasOdd | List HASEven | Longlist | Non-Eddy Result Forum List :: [Integer] - & gt; Result resultFelllist XS | Any strange xs = ListHasOdd | Any xs = ListHasEven | 5 & ​​lt; Length x = long list | Otherwise = noop list HasOdd = (ListHasOdd ==). Results lightlist listSeven = (List HASEven ==). The result is a long list = list (Longlist ==) but it is also stupid: instead of creating a  [bool] , why not use only the  result ?  

Edit: or we can pay attention to what mean

 < Code> listHasOdd xs = a strange Xs listHasEven [] = incorrect listingHess xs = all also xs - if they are not all, then at least one should be strange, and `true 'will give' true 'long _ = false - If there are at least 5 elements in the list - then there is at least one strange element in the list - (and 'list' will be 'true') - or there are also at least five elements in the list - (and 'catalog' TRUE`)    

No comments:

Post a Comment