[Haskell-cafe] Producing MinimumValue
Alexteslin
alexteslin at yahoo.co.uk
Thu Jul 19 13:55:19 EDT 2007
The question suggests to use some functions defined in the section, and one
of them is iSort.
So i used the function but without using higher-order functions - i don't
know though how correct is it?
minimumValue :: [Int] -> Int
minimumValue ns = head (iSort ns)
The other question is to test whether the values of allEqual on inputs 0 to
n are all equal. Again, I defined the method but not sure if its concise?
allEqual :: [Int] -> Bool
allEqual xs = length xs == length (filter isEqual xs)
where
isEqual n = (head xs) == n
Excuse me for questions like these, probably they are not interested ones
but I am just trying to learn the thinking behind the function definitions.
Thank you
Joachim Breitner-2 wrote:
>
> Hi,
>
> Am Mittwoch, den 18.07.2007, 13:42 -0700 schrieb Alexteslin:
>> I am trying to define a function as part of the exercises that gives a
>> result of a minimum value of the input list of ints. Such as this:
>>
>> minimumValue :: [Int] -> Int
>> minimumValue ns ...
>>
>> using either filter or map functions but Not foldr1, because the exercise
>> precedes the section on foldr1.
>> I am confused because using filter - it generates a list on some
>> constraint
>> function for each element.
>>
>> Any hints will be very appreciated. Thank you
>
> Are you allowed to define the function without any of filter or map,
> just yourself?
>
> minimumValue [a] = ...
> minimumValue (x:xs) = .. x .. minimumValue xs ..
>
> Greetings,
> Joachim
>
> --
> Joachim Breitner
> e-Mail: mail at joachim-breitner.de
> Homepage: http://www.joachim-breitner.de
> ICQ#: 74513189
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
--
View this message in context: http://www.nabble.com/Producing-MinimumValue-tf4106379.html#a11694422
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
More information about the Haskell-Cafe
mailing list