[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

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, Alexteslin [EMAIL PROTECTED

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 replace the cons operator (:) with the function you pass

[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 example

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 if the list contains an odd number of elements, the last one

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 taking? Or just a problem from an exam that you're trying to solve for fun

[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

Re: [Haskell-cafe] function unique

2007-07-10 Thread Alexteslin
of it from the list, so it won't get included later. unique2 (x:xs) |elemNum2 x xs == 1 = x:unique2 xs |otherwise = unique2 (deleteElt x xs) I'll let you figure out how to implement the deleteElt function. hope this is helpful! -Brent On 7/10/07, Alexteslin [EMAIL

Re: [Haskell-cafe] function unique

2007-07-11 Thread Alexteslin
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. Thank you. Now that you've done

Re: [Haskell-cafe] function unique

2007-07-11 Thread Alexteslin
[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] - Original Message From: Alexteslin [EMAIL PROTECTED] To: haskell-cafe

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

[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

Re: [Haskell-cafe] Producing MinimumValue

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

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
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 True or False and whatever value i give it produces that value. allEqual :: [Int] - Bool allEqual (x1:x2:xs) = (x1 == x2) allEqual xs allEqual

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 software

[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] 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 am getting this error message: Type error in application Expression :filterAlpha xs

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 don't work. For example: addNum :: Int - (Int - Int) addNum n = addN

Re: [Haskell-cafe] filterFirst

2007-07-25 Thread Alexteslin
the technique is even more valuable. Dan Weston Alexteslin wrote: filterAlpha :: (a - Bool) - [a] - [a] filterAlpha f [] = [] filterAlpha f (x:xs) |f x = x : filterAlpha f xs-- corrected |otherwise = filterAlpha f xs-- corrected

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 line changing from