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:  $ versus . (Lawrence Bottorff)
   2. Re:  $ versus . (Bob Ippolito)
   3.  Defined list data type compared to Haskell List
      (Lawrence Bottorff)
   4. Re:  Defined list data type compared to Haskell   List
      (David McBride)


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

Message: 1
Date: Tue, 26 Jan 2021 10:23:12 -0600
From: Lawrence Bottorff <borg...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] $ versus .
Message-ID:
        <CAFAhFSWv8eS-A6Lgq=ws4nidwbsj5asnv+8v2n8dok-uyxc...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

> :t (init tail)
: error:
:     * Couldn't match expected type `[a]'
:                   with actual type `[a0] -> [a0]'
:     * Probable cause: `tail' is applied to too few arguments
:       In the first argument of `init', namely `tail'
:       In the expression: (init tail)

> :t (init . tail)
: (init . tail) :: [a] -> [a]

> :t init $ tail
: error:
    * Couldn't match expected type `[a]'
                  with actual type `[a0] -> [a0]'
    * Probable cause: `tail' is applied to too few arguments
      In the second argument of `($)', namely `tail'
      In the expression: init $ tail

> chopEnds = init $ tail
> chopEnds [1,2,3]
error: ...
    * Variable not in scope: chopEnds1 :: [Integer] -> t
...

but then

> init $ tail [1,2,3]
[2]

Not sure what I'm missing here. It doesn't make sense to me that the last
expression works, but no version of a closure

chopEnds = init $ tail

does.

On Mon, Jan 25, 2021 at 7:58 PM Kim-Ee Yeoh <k...@atamo.com> wrote:

> init $ tail [1,2,3]
> = init (tail ([1,2,3])) -- a la Lisp
>
> Now, functional programming is awesomest at abstractions. What if we could
> abstract out "init (tail"?
>
> Then we could write
>
> chopEnds = init (tail
>
> But that looks weird. It's only got the left half of a parens pair!
>
> Does that explain why you should not expect the same result?
>
> A separate question is why the compiler even type-checks "init $ tail" in
> the first place. What do you think is going on there?
>
> On Tue, Jan 26, 2021 at 1:16 AM Lawrence Bottorff <borg...@gmail.com>
> wrote:
>
>> I've got this
>>
>> > init $ tail [1,2,3]
>> [2]
>>
>> and this
>>
>> > chopEnds = init $ tail
>> > chopEnds [1,2,3]
>> [1,2]
>>
>> What happened? Why is it not just init $ tail [1,2,3] ?
>>
>> This works fine
>>
>> > chopEnds2 = init . tail
>> > chopEnds2 [1,2,3]
>> [2]
>>
>> What am I missing?
>>
>> LB
>> _______________________________________________
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
> --
> -- Kim-Ee
> _______________________________________________
> 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/20210126/70035314/attachment-0001.html>

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

Message: 2
Date: Tue, 26 Jan 2021 09:25:03 -0800
From: Bob Ippolito <b...@redivi.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] $ versus .
Message-ID:
        <CACwMPm_=7zKpUtkOe6VqMhfNg7cE=gbyyqcbtju5mmr26nj...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

The difference is that one of them is:

— unnecessary parentheses for emphasis
(init tail) [1, 2, 3]

And the other is

— parentheses required for correct evaluation
init (tail [1, 2, 3])

On Tue, Jan 26, 2021 at 08:23 Lawrence Bottorff <borg...@gmail.com> wrote:

> > :t (init tail)
> : error:
> :     * Couldn't match expected type `[a]'
> :                   with actual type `[a0] -> [a0]'
> :     * Probable cause: `tail' is applied to too few arguments
> :       In the first argument of `init', namely `tail'
> :       In the expression: (init tail)
>
> > :t (init . tail)
> : (init . tail) :: [a] -> [a]
>
> > :t init $ tail
> : error:
>     * Couldn't match expected type `[a]'
>                   with actual type `[a0] -> [a0]'
>     * Probable cause: `tail' is applied to too few arguments
>       In the second argument of `($)', namely `tail'
>       In the expression: init $ tail
>
> > chopEnds = init $ tail
> > chopEnds [1,2,3]
> error: ...
>     * Variable not in scope: chopEnds1 :: [Integer] -> t
> ...
>
> but then
>
> > init $ tail [1,2,3]
> [2]
>
> Not sure what I'm missing here. It doesn't make sense to me that the last
> expression works, but no version of a closure
>
> chopEnds = init $ tail
>
> does.
>
> On Mon, Jan 25, 2021 at 7:58 PM Kim-Ee Yeoh <k...@atamo.com> wrote:
>
>> init $ tail [1,2,3]
>> = init (tail ([1,2,3])) -- a la Lisp
>>
>> Now, functional programming is awesomest at abstractions. What if we
>> could abstract out "init (tail"?
>>
>> Then we could write
>>
>> chopEnds = init (tail
>>
>> But that looks weird. It's only got the left half of a parens pair!
>>
>> Does that explain why you should not expect the same result?
>>
>> A separate question is why the compiler even type-checks "init $ tail" in
>> the first place. What do you think is going on there?
>>
>> On Tue, Jan 26, 2021 at 1:16 AM Lawrence Bottorff <borg...@gmail.com>
>> wrote:
>>
>>> I've got this
>>>
>>> > init $ tail [1,2,3]
>>> [2]
>>>
>>> and this
>>>
>>> > chopEnds = init $ tail
>>> > chopEnds [1,2,3]
>>> [1,2]
>>>
>>> What happened? Why is it not just init $ tail [1,2,3] ?
>>>
>>> This works fine
>>>
>>> > chopEnds2 = init . tail
>>> > chopEnds2 [1,2,3]
>>> [2]
>>>
>>> What am I missing?
>>>
>>> LB
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners@haskell.org
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>>
>> --
>> -- Kim-Ee
>> _______________________________________________
>> 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/20210126/2b8a0b6d/attachment-0001.html>

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

Message: 3
Date: Tue, 26 Jan 2021 15:31:22 -0600
From: Lawrence Bottorff <borg...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] Defined list data type compared to
        Haskell List
Message-ID:
        <cafahfsx7_o2rwk20s5ooz8fg0uork2otqmqp+ridcjtwcuq...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I'm following this <https://wiki.haskell.org/99_questions/Solutions/7> and
yet I see this solution

data NestedList a = Elem a | List [NestedList a] deriving (Show)

flatten1 :: NestedList a -> [a]
flatten1 (Elem a   )   = [a]
flatten1 (List (x:xs)) = flatten1 x ++ flatten1 (List xs)
flatten1 (List [])     = []

What I find puzzling is this line

flatten1 (List (x:xs)) = flatten1 x ++ flatten1 (List xs)

where I see

(List (x:xs)) as an argument. How is the NestedList type also able to be
expressed as a normal consed list with x:xs argument? How is (:)
interacting with NestedList?

LB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20210126/72b1f9af/attachment-0001.html>

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

Message: 4
Date: Tue, 26 Jan 2021 16:42:07 -0500
From: David McBride <toa...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Defined list data type compared to
        Haskell List
Message-ID:
        <can+tr43_d7v+o6efr5acxks5-1dzmzj_kbmq21x+hk_2p6v...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

In NestedList, the List constructor takes a regular list of NestedLists.
Therefore when pattern matching on it you can get access to those nested
lists.  In your code, x is the first NestedList, and xs is the rest of the
NestedLists.

On Tue, Jan 26, 2021 at 4:32 PM Lawrence Bottorff <borg...@gmail.com> wrote:

> I'm following this <https://wiki.haskell.org/99_questions/Solutions/7>
> and yet I see this solution
>
> data NestedList a = Elem a | List [NestedList a] deriving (Show)
>
> flatten1 :: NestedList a -> [a]
> flatten1 (Elem a   )   = [a]
> flatten1 (List (x:xs)) = flatten1 x ++ flatten1 (List xs)
> flatten1 (List [])     = []
>
> What I find puzzling is this line
>
> flatten1 (List (x:xs)) = flatten1 x ++ flatten1 (List xs)
>
> where I see
>
> (List (x:xs)) as an argument. How is the NestedList type also able to be
> expressed as a normal consed list with x:xs argument? How is (:)
> interacting with NestedList?
>
> LB
> _______________________________________________
> 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/20210126/12fe9ae9/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 150, Issue 14
******************************************

Reply via email to