Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

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


Today's Topics:

   1. Re:  merge error (trent shipley)
   2. Re:  merge error (Ut Primum)


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

Message: 1
Date: Thu, 17 May 2018 23:04:07 -0700
From: trent shipley <trent.ship...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] merge error
Message-ID:
        <caeflybki4zbzupbp+yt7i89kh1orxrcw0fva2mgwj3femaa...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Thanks to all. I used Mukesh's suggestion.

I am still not clear on:

why [x] /= xs
why first == first@(x:xs), especially weather the variable declarations are
considered names for the same thing.

On Thu, May 17, 2018 at 10:39 PM Hemanth Gunda <hemanth....@gmail.com>
wrote:

> Hi Trent,
>
> This works:
>
> merge:: Ord a => [a] -> [a] -> [a]
> merge [] [] = []
> merge x [] = x
> merge [] y = y
> merge first@(x:xs) second@(y:ys)
> | x <= y = x : merge xs second
> | otherwise = y : merge first ys
>
> Difference in the lines
>
> merge x [] = x
> merge [] y = y
>
> As the input is of type [a] where a belongs to typeclass Ord, you must
> pass x instead of [x].
>
> [x] would work if you tried merge [4] []. but will fail if you tried merge
> [4,5] []. because "4,5" isn't of type a.
>
> Regards, Hemanth
>
>
> On Fri, May 18, 2018 at 10:51 AM trent shipley <trent.ship...@gmail.com>
> wrote:
>
>> The below produces an error. And I am very proud that I could use the
>> GHCi debugging tools to get this far.
>>
>> merge [] [] works.
>>
>> merge [1] [] works.
>>
>> I don't know why the failing example fails. It should return:
>>
>> [4,5]
>>
>> Help to unstuck is appreciated.
>>
>> :step merge [4,5] []
>>
>> *** Exception: ex6_8.hs:(12,1)-(16,66): Non-exhaustive patterns in
>> function merge
>>
>> Given:
>>
>> merge :: Ord a => [a] -> [a] -> [a]
>>
>> merge [] [] = []
>>
>> merge [x] [] = [x]
>>
>> merge [] [y] = [y]
>>
>> merge first@(x:xs) second@(y:ys) | x <= y     = x : merge xs second
>>
>>                                  | otherwise  = y : merge first ys
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20180517/ad3827ec/attachment-0001.html>

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

Message: 2
Date: Fri, 18 May 2018 08:39:48 +0200
From: Ut Primum <utpri...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] merge error
Message-ID:
        <canjdmkk4_odj+3hs7dzxdrtmefo-ce2ofgacznvfopdybbh...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

[x] means a list containing the element x

xs in general is only a variable named xs, and in particular could be a
list; in this case, if you write
first@(x:xs)
you mean that first is a list, its "head" is x and xs is its "tail", i.e.
all the elements of the list first following x.

For example if the arguments of merge are [1,2,4] and [3,6], then
first = [1,2,4]
x=1
xs = [2,4]
second=[3,6]
y=3
ys=[6]

Note that [1,2,4] could not be pattern-matchd with [x]. [6] could (because
contains just one element)

Il ven 18 mag 2018, 08:04 trent shipley <trent.ship...@gmail.com> ha
scritto:

> Thanks to all. I used Mukesh's suggestion.
>
> I am still not clear on:
>
> why [x] /= xs
> why first == first@(x:xs), especially weather the variable declarations
> are considered names for the same thing.
>
> On Thu, May 17, 2018 at 10:39 PM Hemanth Gunda <hemanth....@gmail.com>
> wrote:
>
>> Hi Trent,
>>
>> This works:
>>
>> merge:: Ord a => [a] -> [a] -> [a]
>> merge [] [] = []
>> merge x [] = x
>> merge [] y = y
>> merge first@(x:xs) second@(y:ys)
>> | x <= y = x : merge xs second
>> | otherwise = y : merge first ys
>>
>> Difference in the lines
>>
>> merge x [] = x
>> merge [] y = y
>>
>> As the input is of type [a] where a belongs to typeclass Ord, you must
>> pass x instead of [x].
>>
>> [x] would work if you tried merge [4] []. but will fail if you tried
>> merge [4,5] []. because "4,5" isn't of type a.
>>
>> Regards, Hemanth
>>
>>
>> On Fri, May 18, 2018 at 10:51 AM trent shipley <trent.ship...@gmail.com>
>> wrote:
>>
>>> The below produces an error. And I am very proud that I could use the
>>> GHCi debugging tools to get this far.
>>>
>>> merge [] [] works.
>>>
>>> merge [1] [] works.
>>>
>>> I don't know why the failing example fails. It should return:
>>>
>>> [4,5]
>>>
>>> Help to unstuck is appreciated.
>>>
>>> :step merge [4,5] []
>>>
>>> *** Exception: ex6_8.hs:(12,1)-(16,66): Non-exhaustive patterns in
>>> function merge
>>>
>>> Given:
>>>
>>> merge :: Ord a => [a] -> [a] -> [a]
>>>
>>> merge [] [] = []
>>>
>>> merge [x] [] = [x]
>>>
>>> merge [] [y] = [y]
>>>
>>> merge first@(x:xs) second@(y:ys) | x <= y     = x : merge xs second
>>>
>>>                                  | otherwise  = y : merge first ys
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners@haskell.org
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20180518/782fc7c1/attachment.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 119, Issue 10
******************************************

Reply via email to