Send Beginners mailing list submissions to
[email protected]
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
[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: How to nest arbitrary things (Imants Cekusins)
2. Re: How to nest arbitrary things (Daniel Trstenjak)
3. Re: How to nest arbitrary things (Daniel Trstenjak)
4. Re: How to nest arbitrary things (Imants Cekusins)
5. Re: Pattern matching is actually about matching
constructors?? (Kim-Ee Yeoh)
6. Mixing pattern matching and guards (martin)
7. Re: Mixing pattern matching and guards (Francesco Ariis)
8. Re: Pattern matching is actually about matching
constructors?? (Olumide)
----------------------------------------------------------------------
Message: 1
Date: Mon, 21 Dec 2015 21:56:04 +0100
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How to nest arbitrary things
Message-ID:
<cap1qinzbcdu4rvc6fk9n_rykoeetvsuvxsfq30rqwqwybmk...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
> makeLenses ''Parcel
any cues re: what '' stand for in the above expression?
------------------------------
Message: 2
Date: Mon, 21 Dec 2015 22:17:21 +0100
From: Daniel Trstenjak <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How to nest arbitrary things
Message-ID: <20151221211721.GB2890@octa>
Content-Type: text/plain; charset=iso-8859-1
On Mon, Dec 21, 2015 at 09:06:55PM +0100, Imants Cekusins wrote:
> > a lens with the name 'cans' will be created.
>
> Does Template Haskell modify code file or can these '_' names be used
> throughout the code without visible definition?
In this case Template Haskell doesn't modify the code, fields like
'_cans' are just normal fields and can be used with this name.
There's only the convention that 'makeLenses' creates for every field
with a '_' prefix a lens.
In the case of '_cans' a lens like this will be created:
cans :: Lens' Parcel [Can]
cans = lens getCans setCans
where
getCans parcel = _cans parcel
setCans parcel cans = parcel { _cans = cans }
(This is just an idealized implementation and the real one
will be most likely a bit more sophisticated and optimized.)
> Could we say that lens is a bit like extension to record syntax: allow to
> traverse, get and set properties for structures that are? more complex than
> simple 1 level record?
It's often compared with some kind of jQuery for data structures.
> Why do lens require Template Haskell? Only to generate '_' functions?
To automatically generate the Haskell code like the lens 'cans' in the
above example.
Greetings,
Daniel
------------------------------
Message: 3
Date: Mon, 21 Dec 2015 22:22:44 +0100
From: Daniel Trstenjak <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How to nest arbitrary things
Message-ID: <20151221212244.GA3355@octa>
Content-Type: text/plain; charset=us-ascii
On Mon, Dec 21, 2015 at 09:56:04PM +0100, Imants Cekusins wrote:
> > makeLenses ''Parcel
>
> any cues re: what '' stand for in the above expression?
It's just the escaping of the name needed for Template
Haskell. I think it's the same like calling:
makeLenses "Parcel"
------------------------------
Message: 4
Date: Mon, 21 Dec 2015 22:41:34 +0100
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How to nest arbitrary things
Message-ID:
<CAP1qinZ53yEqrNm7Eu+dZkdzp9q=dc7ayokz_wh4dpt5aod...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Thank you very much Daniel. Lens is a lot clearer now.
jQuery eh?
$(truckContents . _TCBox)
;)
------------------------------
Message: 5
Date: Tue, 22 Dec 2015 12:08:22 +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] Pattern matching is actually about
matching constructors??
Message-ID:
<CAPY+ZdQtcTS9e8bYKFF7z=gx+omaghpbjymjsudpmoyk8k+...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Tue, Dec 22, 2015 at 1:56 AM, Olumide <[email protected]> wrote:
> Is the operator :-: a constructor? I'm confused because the definition of
> :-: is not prefixed by the data keyword?
The confusion is that the pattern-matching for append, i.e. (.++), is done
infix style:
Empty .++ ys = ys
(x :-: xs) .++ ys = x :-: (xs .++ ys)
This defines (.++).
It doesn't define (:-:).
The definition of (.++) pattern matches on (:-:) in (.++)-infix style to do
the job.
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20151222/ea8999fc/attachment-0001.html>
------------------------------
Message: 6
Date: Tue, 22 Dec 2015 06:29:32 +0100
From: martin <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Mixing pattern matching and guards
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Hello all,
I recently wrote this piece of code
import qualified Data.Set as S
[...]
purge :: (Eq cp, Eq ip) => Product cp ip -> Product cp ip
purge (Punion ps)
| ps' == S.empty = Pempty
where ps' = S.filter (/= Pempty) ps
purge x = x
and I thought I had missed the "otherwise" case in the guard and I was prepared
to see a "non exhaustive ..." error, but
to my amazement it works
*Main> purge $ Punion $ S.fromList [Packed 1 Pempty]
Punion (fromList [Packed 1 Pempty])
As this is a Punion, it should match the first pattern, but not the guard. It
seems to fall right through to the second
pattern. Is this the way it works?
------------------------------
Message: 7
Date: Tue, 22 Dec 2015 07:16:14 +0100
From: Francesco Ariis <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Mixing pattern matching and guards
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Tue, Dec 22, 2015 at 06:29:32AM +0100, martin wrote:
> Hello all,
>
> I recently wrote this piece of code
>
> import qualified Data.Set as S
> [...]
> purge :: (Eq cp, Eq ip) => Product cp ip -> Product cp ip
> purge (Punion ps)
> | ps' == S.empty = Pempty
> where ps' = S.filter (/= Pempty) ps
> purge x = x
>
>
> and I thought I had missed the "otherwise" case in the guard and I was
> prepared to see a "non exhaustive ..." error, but
> to my amazement it works
The pattern does match (and any variable bound by it is made available
to the corresponding guards).
Then guards are tried in order: if no guard succeed, the next pattern
match is found (in your case purge x = x, irrefutable).
If you want you can add a catch all guard as last guard:
| ps' == S.empty = Pempty
| otherwise = undefined -- handle ps' /= S.empty here
------------------------------
Message: 8
Date: Tue, 22 Dec 2015 10:53:51 +0000
From: Olumide <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Pattern matching is actually about
matching constructors??
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252; format=flowed
Petr,
Of course you are right. :-: is a value constructor (function) albeit
declared in the infix style a :-: (List a).
Thanks,
- Olumide
On 21/12/15 19:00, Petr V?penka wrote:
> Hello,
>
> actually the definition with data keyword is right there:
>
> infixr 5 :-:
> data List a = Empty | a :-: (List a) deriving (Show, Read, Eq, Ord)
>
> it could be written in prefix form as
>
> data List a = Empty | Cons a (List a) deriving (....)
>
>
> Petr
>
>
>
>
> On Mon, Dec 21, 2015 at 7:56 PM, Olumide <[email protected]
> <mailto:[email protected]>> wrote:
>
> Hello,
>
> On chapter 7 of LYH there's an example of a user-defined operator .++
>
> infixr 5 .++
> (.++) :: List a -> List a -> List a
> Empty .++ ys = ys
> (x :-: xs) .++ ys = x :-: (xs .++ ys)
>
> which is used as follows
>
> let a = 3 :-: 4 :-: 5 :-: Empty
> let b = 6 :-: 7 :-: Empty
> a .++ b
> (:-:) 3 ((:-:) 4 ((:-:) 5 ((:-:) 6 ((:-:) 7 Empty))))
>
> Following this the text reads:
>
> "Notice how we pattern matched on (x :-: xs). That works because
> pattern matching is actually about matching constructors. We can
> match on :-: because it is a constructor for our own list type ..."
> Source:
>
> http://learnyouahaskell.com/making-our-own-types-and-typeclasses#recursive-data-structures
>
> Is the operator :-: a constructor? I'm confused because the
> definition of :-: is not prefixed by the data keyword?
>
> - Olumide
>
> _______________________________________________
> Beginners mailing list
> [email protected] <mailto:[email protected]>
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
>
>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 90, Issue 40
*****************************************