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: Type constructors sharing a common field (Lorenzo Tabacchini)
2. Re: Type constructors sharing a common field (Benjamin Edwards)
3. Re: Type constructors sharing a common field (John M. Dlugosz)
4. Re: Type constructors sharing a common field (Benjamin Edwards)
5. Re: Type constructors sharing a common field (John M. Dlugosz)
6. A little explanation! (Gilberto Melfe)
7. Re: A little explanation! (Kyle Murphy)
8. How to Update Cabal? (Ari King)
----------------------------------------------------------------------
Message: 1
Date: Tue, 29 Apr 2014 07:42:13 +0200
From: Lorenzo Tabacchini <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Type constructors sharing a common
field
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> Yes, there is:
>
> data Person = Child { personAge :: Int, school :: School }
> | Adult { personAge :: Int, job :: Job }
>
>
> No extension needed!
Thanks!
This helps reduce the number of field names, but it does not address the main
problem, which is the obligation of pattern matching on all constructors.
The Person type is just a simple example. If you have a lot of constructors
repeating all of them without a real reason can be time-consuming and boring.
I am aware that the real reason of the problem may be a wrong architecture, but
I still have the feeling that my solution does have some use cases.
------------------------------
Message: 2
Date: Wed, 30 Apr 2014 13:29:02 +0000
From: Benjamin Edwards <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Type constructors sharing a common
field
Message-ID:
<can6k4ngaxykoq7s35y6vh8qcye5yevduvgkpbik3jejukb-...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
>
> Thanks!
> This helps reduce the number of field names, but it does not address the
> main problem, which is the obligation of pattern matching on all
> constructors.
> The Person type is just a simple example. If you have a lot of
> constructors repeating all of them without a real reason can be
> time-consuming and boring.
>
> I am aware that the real reason of the problem may be a wrong
> architecture, but I still have the feeling that my solution does have some
> use cases.
>
If you use a sum type, you *always* need to check every case. That is what
you sign up for. If you want to express a commonality that should expressed
in the type [1]. Otherwise if you extend Person with a constructor that has
*no* notion of age then you cannot have a total function from Person ->
Int. You would want something like a Prism or just a simple function from
Person -> Maybe Int. Try to avoid non-total functions. That way lies
madness.
[1] as has already been suggested, this involves factoring out the things
that are common from the things that aren't
data SomeSum = Part1 String | Part2 Int | Part3
data Common a = Common Int a
data Composite = Common SomeSum
Now you can see that a function wanting the common Int must necessarily
succeed when applied to Composite, but that there is no total function
Composite -> String that accesses the String value held by Part1. I hope
this is useful to you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140430/dfd80e6a/attachment-0001.html>
------------------------------
Message: 3
Date: Wed, 30 Apr 2014 08:38:06 -0500
From: "John M. Dlugosz" <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Type constructors sharing a common
field
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
On 4/29/2014 10:55 AM, Benjamin Edwards wrote:
> |module Mainwhere
>
> import Control.Applicative
> import Control.Lens
>
> main ::IO ()
> main =let p =Child 10
> in print $ p ^. age
>
> data Person =Child Int |Adult Int
>
> age ::Lens' Person Int
> age k (Child x) =Child <$> k x
> age k (Adult x) =Adult <$> k x
> |
Hmm, what does the <$> mean here? I know it for functor application, but I
don't
understand how that works in this example.
------------------------------
Message: 4
Date: Wed, 30 Apr 2014 13:51:56 +0000
From: Benjamin Edwards <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Type constructors sharing a common
field
Message-ID:
<can6k4ngp6mkdal-c4rqtunhvsoger3us_g6y2vwxzpzzdvt...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
>
> Hmm, what does the <$> mean here? I know it for functor application, but
> I don't
> understand how that works in this example.
>
It's a synonym for fmap. Lens' is a type synonym. age really has function
type forall Functor f. (Int -> f Int) -> Person -> f Person. Applying k x
gives me f Int and fmapping the constructor gives me f Person. If you want
to read an excellent but challenging article on why lenses work this way
click here <https://www.fpcomplete.com/user/tel/lenses-from-scratch>.
Otherwise the signature should give you enough to be able to play type
tetris to figure out where the fmap comes in (hopefully). This isn't super
beginner friendly, but it's where haskell seems to be headed these days.
Ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140430/94bb94ad/attachment-0001.html>
------------------------------
Message: 5
Date: Wed, 30 Apr 2014 09:54:27 -0500
From: "John M. Dlugosz" <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Type constructors sharing a common
field
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252; format=flowed
On 4/29/2014 12:42 AM, Lorenzo Tabacchini wrote:
>> Yes, there is:
>>
>> data Person = Child { personAge :: Int, school :: School }
>> | Adult { personAge :: Int, job :: Job }
>>
>>
>> No extension needed!
>
>
> Thanks!
> This helps reduce the number of field names, but it does not address the main
> problem,
> which is the obligation of pattern matching on all constructors.
> The Person type is just a simple example. If you have a lot of constructors
> repeating all
> of them without a real reason can be time-consuming and boring.
>
> I am aware that the real reason of the problem may be a wrong architecture,
> but I still
> have the feeling that my solution does have some use cases.
>
That reminds me of database design: Normalize! In this case, Daniel's
suggestion is in
line with the theory. With varying numbers of fields between the different
kinds of
people, it suggests making separate tables and joining them to produce the
child or adult
views.
More generally, perhaps database schema rather than Object Oriented is a better
place to
transfer engineering skills from when it comes to designing the information
model.
?John
------------------------------
Message: 6
Date: Wed, 30 Apr 2014 16:29:25 +0100
From: Gilberto Melfe <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] A little explanation!
Message-ID:
<CAH5k6k482c7t-Rt9C4FXMdYRV_=sjybsqesfaqtw2fc4duw...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hello everybody !
Could someone explain me exactly how this function works?
elementAt_w'pf = (last .) . take . (+ 1)
It's a posted solution to: 99 Haskell problems, problem 3.
I'm having trouble with the "(last .) ." thing!
Hope someone can help!
Thank You!
Gilberto
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140430/6c7b4598/attachment-0001.html>
------------------------------
Message: 7
Date: Wed, 30 Apr 2014 11:53:29 -0400
From: Kyle Murphy <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] A little explanation!
Message-ID:
<ca+y6jcxqtad_wkjae-yxfcek0q5s1rzd2oiac6w4etfb2+5...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Near as I can tell, this is basically having to do with partial application
and the order of precedence for the (.) operator. A great way to look at
this stuff is using the :t command in GHCi and checking out the types
involved.
Prelude> :t (.)
(.) :: (b -> c) -> (a -> b) -> a -> c
Prelude> :t last
last :: [a] -> a
Prelude> :t (last .)
(last .) :: (a -> [c]) -> a -> c
Looking back at the type for (.) and plugging in "[a]" in place of "b" and
"a" in place of "c" we get:
([b] -> b) -> (a -> [b]) -> a -> b
and since "last" takes the place of the first function we can reduce that
to:
(a -> [b]) -> a -> b
GHCi used "c" where we used "b" but you can clearly see the signatures are
identical other than that detail.
What we're left with is, (last .) is used to take a function from some type
"a" that returns a list of type "b", and a "a" value, and then returns the
last value from that list of "b" types.
-R. Kyle Murphy
--
Curiosity was framed, Ignorance killed the cat.
On Wed, Apr 30, 2014 at 11:29 AM, Gilberto Melfe <[email protected]>wrote:
> Hello everybody !
>
> Could someone explain me exactly how this function works?
>
> elementAt_w'pf = (last .) . take . (+ 1)
>
> It's a posted solution to: 99 Haskell problems, problem 3.
>
> I'm having trouble with the "(last .) ." thing!
>
> Hope someone can help!
>
> Thank You!
>
> Gilberto
>
> _______________________________________________
> 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/20140430/4649c3b2/attachment-0001.html>
------------------------------
Message: 8
Date: Wed, 30 Apr 2014 12:18:08 -0400
From: Ari King <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] How to Update Cabal?
Message-ID:
<CAPcS2ajYqvTgFLum2vML7CYgxpO=s9w1cmqw4illykaon9a...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi,
I installed the haskell platform for ubuntu, which contains cabal-install
version 1.16.0.2
I'd like to use sandboxes, which as I understand is available in versions
>= 1.18.
Is it best to clone the cabal git repo and install as described
here<http://coldwa.st/e/blog/2013-08-20-Cabal-sandbox.html>?
In which case, should I remove the existing cabal installation from
"/usr/bin"?
Best,
Ari
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140430/bb8c19d5/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 70, Issue 55
*****************************************