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: Question on (x:xs) form (Brandon Allbery)
2. Re: Question on (x:xs) form (Kim-Ee Yeoh)
3. Re: Question on (x:xs) form (Denis Albuquerque)
4. breaking code to several lines (Miro Karpis)
5. Re: breaking code to several lines (Brandon Allbery)
6. Re: breaking code to several lines (David McBride)
----------------------------------------------------------------------
Message: 1
Date: Mon, 23 Dec 2013 10:03:26 -0500
From: Brandon Allbery <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Question on (x:xs) form
Message-ID:
<cakfcl4vy3tiaamxge3hzmp+nmnsu7mjquwxaseh81ffquom...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Mon, Dec 23, 2013 at 9:57 AM, Angus Comber <[email protected]> wrote:
> Why are the brackets required? And what do they signify?
> Eg reverse' x:xs = reverse' xs ++ [x] results in a parse error.
>
If you leave them off then it's parsed as three parameters instead of a
pattern as a single parameter. But that also leads to a parse error since
you can't use a bare operator that way. Which is "weird", but you can get
into inconsistent parses if you try to guess that the parentheses are
needed: should it be `(x:xs)` a pattern, or should it be `x (:) xs` 3
patterns with an infix constructor as the second?
--
brandon s allbery kf8nh sine nomine associates
[email protected] [email protected]
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131223/b6ea37b1/attachment-0001.html>
------------------------------
Message: 2
Date: Mon, 23 Dec 2013 22:56:24 +0700
From: Kim-Ee Yeoh <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Question on (x:xs) form
Message-ID:
<CAPY+ZdSXJGBGNCOd+ZVzWP=qg4g4w3u9xhgpiou7zmve9pu...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
On Mon, Dec 23, 2013 at 9:57 PM, Angus Comber <[email protected]> wrote:
> Why are the brackets required? And what do they signify?
>
> Eg reverse' x:xs = reverse' xs ++ [x] results in a parse error.
>
So a number of Haskell-specific themes are relevant here, especially if you
come from a Lisp background:
* types (but you knew that already!)
* pattern-matching & exhaustivity of matches
* operator infix notation
* associativity precedence
* special notation for lists
It's a good idea to watch out for all of the above when learning the
language. It helps to have some google-able names when the situation is
ripe for drilling deep into these topics.
To elaborate a bit,
Special List Notation: lists use (:) and [x]. But this syntax is baked
specially into the language definition! If you define your own list, it'll
typically look like
data List a = Nil | Cons a (List a) -- note the parens!
The alternative GADT-ish style may make this clearer:
data List a where
Nil :: List a
Cons :: a -> List a -> List a
Nil and Cons are data constructor *functions*, and because and only because
they are so, do they get to have Capitalized Names. <------- this is
another big WTF that trips up many, many learners. Especially with code
like:
newtype X a = X a -- whaaaa????? (It's ok, you'll get it soon enough.)
Back to reverse'. With our user-defined List a, reverse' will look like
reverse' Nil =
reverse' (Cons x xs) = ... -- again note the parens!
(There is however, *NO* difference in the semantics. The code just looks
different but the compiler doesn't care.)
Note how the pattern-matching includes every single case of the sum-type;
here both of them: Nil and Cons. This is Generally A Good Thing!
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131223/f6841861/attachment-0001.html>
------------------------------
Message: 3
Date: Mon, 23 Dec 2013 16:55:35 -0200
From: Denis Albuquerque <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Question on (x:xs) form
Message-ID:
<cagfjek4x5rymnqchterfd-qhrpst9n0vkhqmgh4refgfwsw...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Hi Angus,
you need to put the parentheses around the pattern x:xs because the
application reverse' has priority over (:) , so the statement is the
same as
(reverse' x):xs = reverse' xs ++ [x]
and results the error.
-- Denis.
On Mon, Dec 23, 2013 at 12:57 PM, Angus Comber <[email protected]> wrote:
> Eg for a definition of reverse:
>
> reverse' :: [a] -> [a]
> reverse' [] = []
> reverse' (x:xs) = reverse' xs ++ [x]
>
> In the last line of the definition, x is an element in the list (the first
> element) and xs represents the remainder of the list.
>
> so if list was [1,2,3] then x is 1 and xs is [2,3]
>
> Why are the brackets required? And what do they signify?
>
> Eg reverse' x:xs = reverse' xs ++ [x] results in a parse error.
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 4
Date: Mon, 23 Dec 2013 22:42:47 +0100
From: Miro Karpis <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] breaking code to several lines
Message-ID:
<CAJnnbxEFJopPF-3s5joa9=x7usmznhro+t73u+kkb05owef...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Hi please,... I have one sql insert statement which is too long to be on
one line. Is there a way that I can break it several lines? Or does it have
to be everything in one line?
here is the query:
execute_ conn "INSERT INTO ttableXY
(column1, column2, column3, column4, column5, column6, column7) VALUES
('var1', 'var2', 'var3', 'var4', 'var5', 'var6', 'var7')"
Thanks,
Miro
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131223/82cd8f13/attachment-0001.html>
------------------------------
Message: 5
Date: Mon, 23 Dec 2013 16:47:12 -0500
From: Brandon Allbery <[email protected]>
To: Miro Karpis <[email protected]>, The Haskell-Beginners
Mailing List - Discussion of primarily beginner-level topics related
to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] breaking code to several lines
Message-ID:
<cakfcl4vws_y-g10m4kyn6fex4zqv9dtqk7+_abw1857m5pg...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Mon, Dec 23, 2013 at 4:42 PM, Miro Karpis <[email protected]>wrote:
> Hi please,... I have one sql insert statement which is too long to be on
> one line. Is there a way that I can break it several lines? Or does it have
> to be everything in one line?
>
See "string gaps" in
http://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-200002.6
--
brandon s allbery kf8nh sine nomine associates
[email protected] [email protected]
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131223/9501238e/attachment-0001.html>
------------------------------
Message: 6
Date: Mon, 23 Dec 2013 16:57:48 -0500
From: David McBride <[email protected]>
To: [email protected], The Haskell-Beginners Mailing List -
Discussion of primarily beginner-level topics related to Haskell
<[email protected]>
Subject: Re: [Haskell-beginners] breaking code to several lines
Message-ID:
<CAN+Tr40N91c3a7P0y-zz6ew=BFJROC2TWStzpMXMskhYn=l...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Another option is a string quasiquoter. There are several options
available, non interpolating ones ones such as string-qq or string-quote,
as well as ones that allow you to interpolate variables, like
interpolatedstring-qq.
On Mon, Dec 23, 2013 at 4:42 PM, Miro Karpis <[email protected]>wrote:
> Hi please,... I have one sql insert statement which is too long to be on
> one line. Is there a way that I can break it several lines? Or does it have
> to be everything in one line?
>
> here is the query:
> execute_ conn "INSERT INTO ttableXY
> (column1, column2, column3, column4, column5, column6, column7) VALUES
> ('var1', 'var2', 'var3', 'var4', 'var5', 'var6', 'var7')"
>
> Thanks,
> Miro
>
> _______________________________________________
> 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/20131223/0ff6c698/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 66, Issue 17
*****************************************