function defenition. Do I understand it right?

Hello, I have made a exercise where I must split a even list. The answer is : halve xs = (take n xs drop n xs) where n = length xs 'div' 2 Now I want to change it so i can split even and not even list,. I thought this can be the answer halve xs = lenght xs 'mod' 2 = 0 : (take n xs drop n xs) otherwise : (take n+1 xs drop n+1 xs) where n = length xs 'div' 2 Can this be working ? I did not check this on GCHI because Im re - installing my OS. Regards. Roelof

For simple snippets like this, you can go to
http://codepad.org/ddySVOPr and run your code to see if it works.
And your first version (once corrected for syntax) works on any list
length except for empty lists.
On Mon, Jul 11, 2011 at 10:48 AM, Roelof Wobben
Hello,
I have made a exercise where I must split a even list. The answer is :
halve xs = (take n xs drop n xs) where n = length xs 'div' 2
Now I want to change it so i can split even and not even list,. I thought this can be the answer
halve xs = lenght xs 'mod' 2 = 0 : (take n xs drop n xs) otherwise : (take n+1 xs drop n+1 xs) where n = length xs 'div' 2
Can this be working ? I did not check this on GCHI because Im re - installing my OS.
Regards.
Roelof
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Hello, Thanks for the tip. Im stuck now. I have this : halve (xs) | length xs'mod'2 == 0 = (take n xs drop n xs) | otherwise = (take n+1 xs drop n+1 xs where n= lenght xs'div'2 main = do putStrLn $ show $ halve [1,2,3,4] putStrLn $ show $ halve [1,2,3] But now I get this message : ERROR line 3 - Syntax error in expression (unexpected keyword "where") Appearently I can't use where here. How can I solve this ? Roelof
Date: Mon, 11 Jul 2011 11:44:28 -0400 Subject: Re: [Haskell-beginners] function defenition. Do I understand it right? From: dmcbride@neondsl.com To: rwobben@hotmail.com CC: beginners@haskell.org
For simple snippets like this, you can go to http://codepad.org/ddySVOPr and run your code to see if it works.
And your first version (once corrected for syntax) works on any list length except for empty lists.
On Mon, Jul 11, 2011 at 10:48 AM, Roelof Wobben
wrote: Hello,
I have made a exercise where I must split a even list. The answer is :
halve xs = (take n xs drop n xs) where n = length xs 'div' 2
Now I want to change it so i can split even and not even list,. I thought this can be the answer
halve xs = lenght xs 'mod' 2 = 0 : (take n xs drop n xs) otherwise : (take n+1 xs drop n+1 xs) where n = length xs 'div' 2
Can this be working ? I did not check this on GCHI because Im re - installing my OS.
Regards.
Roelof
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Hi.
On 11 July 2011 18:44, David McBride
And your first version (once corrected for syntax) works on any list length except for empty lists.
Why wouldn't it work for empty lists? For example with the following definition: halve xs = let n = length xs `div` 2 in (take n xs, drop n xs) Best, Ozgur

Because I tried it and it didn't work. But it turns out it does work
and it was just an ambiguous variable error from using empty list.
Codepad had a weird error, they must be using an old version of ghc or
something.
On Mon, Jul 11, 2011 at 6:17 PM, Ozgur Akgun
Hi.
On 11 July 2011 18:44, David McBride
wrote: And your first version (once corrected for syntax) works on any list length except for empty lists.
Why wouldn't it work for empty lists? For example with the following definition: halve xs = let n = length xs `div` 2 in (take n xs, drop n xs)
Best, Ozgur

Codepad uses Hugs, according to their about page. Makes me terribly glad that the error messages in GHC are so much more informative. On Jul 11, 2011, at 7:11 PM, David McBride wrote:
Because I tried it and it didn't work. But it turns out it does work and it was just an ambiguous variable error from using empty list. Codepad had a weird error, they must be using an old version of ghc or something.
On Mon, Jul 11, 2011 at 6:17 PM, Ozgur Akgun
wrote: Hi.
On 11 July 2011 18:44, David McBride
wrote: And your first version (once corrected for syntax) works on any list length except for empty lists.
Why wouldn't it work for empty lists? For example with the following definition: halve xs = let n = length xs `div` 2 in (take n xs, drop n xs)
Best, Ozgur
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
participants (4)
-
David McBride
-
Jack Henahan
-
Ozgur Akgun
-
Roelof Wobben