Re: [Haskell-cafe] defining mapPairs function

2007-09-01 Thread Alexteslin
Brent Yorgey wrote: > > On 8/29/07, Alexteslin <[EMAIL PROTECTED]> wrote: >> >> >> Hello, >> >> I just came across with this question on the exam and can not think of >> implementing it. > > > Wait, is this an exam for a class you&#

Re: [Haskell-cafe] defining mapPairs function

2007-08-29 Thread Alexteslin
Alexteslin wrote: > > Hello, > > I just came across with this question on the exam and can not think of > implementing it. > > mapPair :: (a -> a -> a) -> [a] -> [a] > > such that mapPairs f [x1, x2, x3, x4...] = [f x1 x2, f x3 x4,...] > > and i

[Haskell-cafe] defining mapPairs function

2007-08-29 Thread Alexteslin
Hello, I just came across with this question on the exam and can not think of implementing it. mapPair :: (a -> a -> a) -> [a] -> [a] such that mapPairs f [x1, x2, x3, x4...] = [f x1 x2, f x3 x4,...] and if the list contains an odd number of elements, the last one is kept unchanged, for exampl

Re: [Haskell-cafe] defining last using foldr

2007-08-15 Thread Alexteslin
Aaron Denney wrote: > > (Quoting reformatted. Try to have your responses below what you are > responding to. It makes it easier to read as a conversation.) > > On 2007-08-14, Alexteslin <[EMAIL PROTECTED]> wrote: >> Aaron Denney wrote: >>> Folds repl

Re: [Haskell-cafe] defining last using foldr

2007-08-14 Thread Alexteslin
Well, i have tried cons (:) operator but when it passed to foldr doesn't work because cons operator operates first character and then the list but the foldr argument takes a function (a->a->a). Maybe i am missing the point here? Aaron Denney wrote: > > On 2007-08-14, A

[Haskell-cafe] defining last using foldr

2007-08-14 Thread Alexteslin
Hi, I am trying to do the exercise which asks to define built-in functions 'last' and 'init' using 'foldr' function, such as last "Greggery Peccary" = 'y' the type for my function is: myLast :: [Char] -> Char I am not generalizing type so that make it less complicated. But what ever i am tr

Re: [Haskell-cafe] Primitive Recursive Algebraic Types

2007-08-02 Thread Alexteslin
Alexteslin wrote: > > Hi, I am doing some simple exercises about recursive algebraic types and > this particular exercise asks to define a function which counts the number > of operators in an expression. I defined the function below, but i am not > sure if on the second lin

[Haskell-cafe] Primitive Recursive Algebraic Types

2007-08-02 Thread Alexteslin
Hi, I am doing some simple exercises about recursive algebraic types and this particular exercise asks to define a function which counts the number of operators in an expression. I defined the function below, but i am not sure if on the second line changing from "evalLength (Lit n) = n" to "(Lit

Re: [Haskell-cafe] Printing the function result

2007-07-25 Thread Alexteslin
Thank you guys, i didn't understand the concept of the chapter. Brent Yorgey wrote: > > On 7/25/07, Alexteslin <[EMAIL PROTECTED]> wrote: >> >> >> Hi, >> >> I am going through examples from the textbook and trying them out but >> some >&

[Haskell-cafe] Printing the function result

2007-07-25 Thread Alexteslin
Hi, I am going through examples from the textbook and trying them out but some don't work. For example: addNum :: Int -> (Int -> Int) addNum n = addN where addN m = n+m This error message i am getting: ERROR - Cannot find "show" function for: *** Expression : addNum 4 *** Of ty

Re: [Haskell-cafe] filterFirst

2007-07-25 Thread Alexteslin
that f never changes if it is defined in only one spot. > > Later, when you study monads you will notice the same pattern in the > Reader monad, where the technique is even more valuable. > > Dan Weston > > Alexteslin wrote: >> >> filterAlpha :: (a -> B

Re: [Haskell-cafe] filterFirst

2007-07-23 Thread Alexteslin
apfelmus wrote: > > Alexteslin wrote: >> filterAlpha :: (a -> Bool) -> [a] -> [a] >> filterAlpha f [] = [] >> filterAlpha f (x:xs) >> |f x= x : filterAlpha xs >> |otherwise = filterAlpha xs >> >> >> and i

[Haskell-cafe] filterFirst

2007-07-23 Thread Alexteslin
Hi, first I like to thank all of you guys - it really helps! I am still on a same chapter with higher order functions and this function is also confusing. But before i even define this function i am getting the type error - i don't know why? So i wrote the simpler one like: filterAlpha :: (a ->

Re: [Haskell-cafe] Producing MinimumValue

2007-07-19 Thread Alexteslin
What wrong with my original solution? allEqual2 :: [Int] -> Bool allEqual2 xs = length xs == length (filter isEqual xs) where isEqual n = (head xs) == n It looks simpler to me Dan Weston wrote: > > The real lesson here is that > > 1) no problem is "too easy" to cheat good sof

Re: [Haskell-cafe] Producing MinimumValue

2007-07-19 Thread Alexteslin
tually-exclusive patterns are listed, so > I find it clearer to put the base case of an induction first, so I don't > forget it. > > Dan > > Alexteslin wrote: >> I have defined the first line it seems right to me but second line not >> sure. >> I have Tr

Re: [Haskell-cafe] Producing MinimumValue

2007-07-19 Thread Alexteslin
I have defined the first line it seems right to me but second line not sure. I have True or False and whatever value i give it produces that value. allEqual :: [Int] -> Bool allEqual (x1:x2:xs) = (x1 == x2) && allEqual xs allEqual _ = ??? Steve Schafer wrote: > > On Thu, 19 Jul 2007

Re: [Haskell-cafe] Producing MinimumValue

2007-07-19 Thread Alexteslin
obably 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 exe

[Haskell-cafe] Producing MinimumValue

2007-07-18 Thread Alexteslin
Hello, 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 fol

Re: [Haskell-cafe] function unique

2007-07-11 Thread Alexteslin
Oh, I am lost now - for now anyway. I am attempting to do next exercise in the book to define reverse function using primitive recursion and pattern matching on lists. But getting stack because when i con in front of xs (xs:x) i get en error, which i thought i would be getting anyway. I tried

Re: [Haskell-cafe] function unique

2007-07-11 Thread Alexteslin
quot;input list" is really [1,4,5,3] but you > can get this with head and tail). I'm just learning about the fold family > myself. - Greg > > Prelude> foldl (\a b -> if (any (\x -> x == b) a) then a else b:a) [1] > [4,5,3,3,4] > [3,5,4,1] > > > &

Re: [Haskell-cafe] function unique

2007-07-11 Thread Alexteslin
|x == y = deleteElem x ys |otherwise = y:deleteElem x ys And I did think about for every call it will go through an entire list - now i know where the solution lies. Thanks again Dan Weston wrote: > > Alexteslin wrote: > > I'v got it - it produces the right output. > >

Re: [Haskell-cafe] function unique

2007-07-10 Thread Alexteslin
ut how to implement the deleteElt function. > > hope this is helpful! > -Brent > > On 7/10/07, Alexteslin <[EMAIL PROTECTED]> wrote: >> >> >> Hi, i am a beginner to Haskell and i have a beginner's question to ask. >> >> An exercise asks t

[Haskell-cafe] function unique

2007-07-10 Thread Alexteslin
Hi, i am a beginner to Haskell and i have a beginner's question to ask. An exercise asks to define function unique :: [Int] -> [Int], which outputs a list with only elements that are unique to the input list (that appears no more than once). I defined a function with list comprehension which wor