Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  function defenition. Do I understand it      right?
      (David McBride)
   2. Re:  function defenition. Do I understand it      right? (Ozgur Akgun)
   3. Re:  function defenition. Do I understand it      right? (David Place)
   4. Re:  function defenition. Do I understand it      right?
      (David McBride)
   5. Re:  function defenition. Do I understand it      right? (Jack Henahan)
   6. Re:  function defenition. Do I understand it right?
      (Roelof Wobben)
   7. Re:  function defenition. Do I understand it      right?
      (Benjamin Edwards)
   8. Re:  function defenition. Do I understand it right?
      (Roelof Wobben)


----------------------------------------------------------------------

Message: 1
Date: Mon, 11 Jul 2011 17:49:10 -0400
From: David McBride <[email protected]>
Subject: Re: [Haskell-beginners] function defenition. Do I understand
        it      right?
To: Roelof Wobben <[email protected]>
Cc: [email protected]
Message-ID:
        <CAN+Tr416L4gga3r_ga5b8JVU+DS_HVRrwDy5Dm6PrM3=kxq...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

You are missing a parenthesis in your otherwise alternative, right
before the where.

There are a few other problems including, you are using single quotes
' instead of back quotes ` for your mod functions, and you don't have
commas in between the elements of your pairs.

Despite that the algorithm needs a bit more work to do what you want,
but you are close:  http://codepad.org/9pA4cLwb

On Mon, Jul 11, 2011 at 5:13 PM, Roelof Wobben <[email protected]> wrote:
>
> Hello,
>
>
>
> I had a look at it but I don't think it will solve my problem.
>
> What I try to achieve is this:
>
>
>
> [1,2,3,4] will be [1,2] [3,4]
>
> [1,2,3,4,5] will be [1,2,3] [3,4,5]
>
>
>
> So the halfs have to be the same lenght.
>
>
>
> So I use :
>
>
>
> length xs'div' 2 to figure out where the middle is.
>
> lenght xs'mod'2 to look if it's a even or not even list.
>
>
>
> So I can use splitat but then the lists will not be the same length if it's a 
> not even list.
>
>
>
> Roelof
>
>
>
> ----------------------------------------
>> Subject: Re: [Haskell-beginners] function defenition. Do I understand it 
>> right?
>> From: [email protected]
>> Date: Mon, 11 Jul 2011 15:55:13 -0400
>> To: [email protected]
>>
>> You're overcomplicating things. Look at splitAt from Data.List:
>>
>> http://hackage.haskell.org/packages/archive/base/4.1.0.0/doc/html/Data-List.html#v%3AsplitAt
>>
>> On Jul 11, 2011, at 3:51 PM, Roelof Wobben wrote:
>>
>> > 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: [email protected]
>> > > To: [email protected]
>> > > CC: [email protected]
>> > >
>> > > 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 <[email protected]> 
>> > > 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
>> > > > [email protected]
>> > > > http://www.haskell.org/mailman/listinfo/beginners
>> > > >
>> > > >
>> > _______________________________________________
>> > Beginners mailing list
>> > [email protected]
>> > http://www.haskell.org/mailman/listinfo/beginners
>>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



------------------------------

Message: 2
Date: Tue, 12 Jul 2011 01:17:30 +0300
From: Ozgur Akgun <[email protected]>
Subject: Re: [Haskell-beginners] function defenition. Do I understand
        it      right?
To: David McBride <[email protected]>
Cc: [email protected]
Message-ID:
        <calzazpcaz9ck3zqmjnkbc6tlpifz+hsygkpbnvaydm2w0ul...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi.

On 11 July 2011 18:44, David McBride <[email protected]> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110712/897ecf1e/attachment-0001.htm>

------------------------------

Message: 3
Date: Mon, 11 Jul 2011 18:56:42 -0400
From: David Place <[email protected]>
Subject: Re: [Haskell-beginners] function defenition. Do I understand
        it      right?
To: Roelof Wobben <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Jul 11, 2011, at 5:13 PM, Roelof Wobben wrote:

> What I try to achieve is this:
> 
> 
> 
> [1,2,3,4] will be [1,2] [3,4]
> 
> [1,2,3,4,5] will be [1,2,3] [3,4,5]

So, I think what you want is this http://codepad.org/kjpbtLfR 

Is that correct?



------------------------------

Message: 4
Date: Mon, 11 Jul 2011 19:11:27 -0400
From: David McBride <[email protected]>
Subject: Re: [Haskell-beginners] function defenition. Do I understand
        it      right?
To: Ozgur Akgun <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID:
        <can+tr40sv-wag2ttgnyuvevb3k6kzeuguqbgt-esvyyfsfn...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

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 <[email protected]> wrote:
> Hi.
>
> On 11 July 2011 18:44, David McBride <[email protected]> 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
>



------------------------------

Message: 5
Date: Mon, 11 Jul 2011 19:38:00 -0400
From: Jack Henahan <[email protected]>
Subject: Re: [Haskell-beginners] function defenition. Do I understand
        it      right?
To: David McBride <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

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 <[email protected]> wrote:
>> Hi.
>> 
>> On 11 July 2011 18:44, David McBride <[email protected]> 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
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners




------------------------------

Message: 6
Date: Tue, 12 Jul 2011 09:02:48 +0000
From: Roelof Wobben <[email protected]>
Subject: Re: [Haskell-beginners] function defenition. Do I understand
        it right?
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"




hello
 


Everyone thanks for the help.
 
I'm now trying to make this work on a empty list.
 


But my question is.
 
When the definition is :
 


[a] -> [a] [a]
 


Is it correct that I don't can use.
 


length xs = 0 | [] 

 

Roelof
 
----------------------------------------
> Subject: Re: [Haskell-beginners] function defenition. Do I understand it 
> right?
> From: [email protected]
> Date: Mon, 11 Jul 2011 18:56:42 -0400
> CC: [email protected]
> To: [email protected]
>
> On Jul 11, 2011, at 5:13 PM, Roelof Wobben wrote:
>
> > What I try to achieve is this:
> >
> >
> >
> > [1,2,3,4] will be [1,2] [3,4]
> >
> > [1,2,3,4,5] will be [1,2,3] [3,4,5]
>
> So, I think what you want is this http://codepad.org/kjpbtLfR
>
> Is that correct?                                        


------------------------------

Message: 7
Date: Tue, 12 Jul 2011 10:34:25 +0100
From: Benjamin Edwards <[email protected]>
Subject: Re: [Haskell-beginners] function defenition. Do I understand
        it      right?
To: Roelof Wobben <[email protected]>
Cc: [email protected]
Message-ID:
        <CAN6k4njKr2vLVyE5rb-MVKL2s-VDP6epqtp38F60D_6=oxw...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I don't even understand what you are trying to do :)

if you want to pattern match on the empty list

foo :: [a] -> [a]
foo [] = 0
foo (x:xs) = undefined

if you want to use the guard syntax

foo xs | null xs = 0
          | otherwise = undefined


Ben

On 12 July 2011 10:02, Roelof Wobben <[email protected]> wrote:

>
>
>
> hello
>
>
>
> Everyone thanks for the help.
>
> I'm now trying to make this work on a empty list.
>
>
>
> But my question is.
>
> When the definition is :
>
>
>
> [a] -> [a] [a]
>
>
>
> Is it correct that I don't can use.
>
>
>
> length xs = 0 | []
>
>
>
> Roelof
>
> ----------------------------------------
> > Subject: Re: [Haskell-beginners] function defenition. Do I understand it
> right?
> > From: [email protected]
> > Date: Mon, 11 Jul 2011 18:56:42 -0400
> > CC: [email protected]
> > To: [email protected]
> >
> > On Jul 11, 2011, at 5:13 PM, Roelof Wobben wrote:
> >
> > > What I try to achieve is this:
> > >
> > >
> > >
> > > [1,2,3,4] will be [1,2] [3,4]
> > >
> > > [1,2,3,4,5] will be [1,2,3] [3,4,5]
> >
> > So, I think what you want is this http://codepad.org/kjpbtLfR
> >
> > Is that correct?
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110712/3357faf8/attachment-0001.htm>

------------------------------

Message: 8
Date: Tue, 12 Jul 2011 09:44:05 +0000
From: Roelof Wobben <[email protected]>
Subject: Re: [Haskell-beginners] function defenition. Do I understand
        it right?
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"


Oke, 

 

I have now this as function definition.

 



halve (xs) | length 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 


main = do
  putStrLn $ show $ halve [1,2,3,4]
  putStrLn $ show $ halve [1,2,3]
  

 

this one works except for empty lists.

So I thought this would work .

 

halve (xs) | length xs == 0 = []

           | length 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 

 

 

but then I see this error : 

 

 

Error occurred
ERROR line 2 - Type error in guarded expression
*** Term           : (take n xs,drop n xs)
*** Type           : ([b],[b])
*** Does not match : [a]

 

So I assume that a function must always have the same output and can't have 1 
or 2 lists as output.

 

Is this the right assumption.

 

Roelof


________________________________
> Date: Tue, 12 Jul 2011 10:34:25 +0100 
> Subject: Re: [Haskell-beginners] function defenition. Do I understand 
> it right? 
> From: [email protected] 
> To: [email protected] 
> CC: [email protected] 
> 
> I don't even understand what you are trying to do :) 
> 
> if you want to pattern match on the empty list 
> 
> foo :: [a] -> [a] 
> foo [] = 0 
> foo (x:xs) = undefined 
> 
> if you want to use the guard syntax 
> 
> foo xs | null xs = 0 
> | otherwise = undefined 
> 
> 
> Ben 
> 
> On 12 July 2011 10:02, Roelof Wobben 
> <[email protected]<mailto:[email protected]>> wrote: 
> 
> 
> 
> hello 
> 
> 
> 
> Everyone thanks for the help. 
> 
> I'm now trying to make this work on a empty list. 
> 
> 
> 
> But my question is. 
> 
> When the definition is : 
> 
> 
> 
> [a] -> [a] [a] 
> 
> 
> 
> Is it correct that I don't can use. 
> 
> 
> 
> length xs = 0 | [] 
> 
> 
> 
> Roelof 
> 
> ---------------------------------------- 
> > Subject: Re: [Haskell-beginners] function defenition. Do I understand 
> it right? 
> > From: [email protected]<mailto:[email protected]> 
> > Date: Mon, 11 Jul 2011 18:56:42 -0400 
> > CC: [email protected]<mailto:[email protected]> 
> > To: [email protected]<mailto:[email protected]> 
> > 
> > On Jul 11, 2011, at 5:13 PM, Roelof Wobben wrote: 
> > 
> > > What I try to achieve is this: 
> > > 
> > > 
> > > 
> > > [1,2,3,4] will be [1,2] [3,4] 
> > > 
> > > [1,2,3,4,5] will be [1,2,3] [3,4,5] 
> > 
> > So, I think what you want is this http://codepad.org/kjpbtLfR 
> > 
> > Is that correct? 
> _______________________________________________ 
> Beginners mailing list 
> [email protected]<mailto:[email protected]> 
> http://www.haskell.org/mailman/listinfo/beginners 
>                                         


------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 37, Issue 19
*****************************************

Reply via email to