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 (Frerich Raabe)
2. Re: Type constructors sharing a common field (Michael Orlitzky)
3. Re: Type constructors sharing a common field (Lorenzo Tabacchini)
4. Re: Type constructors sharing a common field (Lorenzo Tabacchini)
5. Re: Type constructors sharing a common field (Benjamin Edwards)
6. Re: development workflow ? (Chadda? Fouch?)
7. Functors in Haskell (Dimitri DeFigueiredo)
8. Re: Functors in Haskell (Rein Henrichs)
----------------------------------------------------------------------
Message: 1
Date: Tue, 29 Apr 2014 14:08:27 +0200
From: Frerich Raabe <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Type constructors sharing a common
field
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
On 2014-04-28 20:26, Lorenzo Tabacchini wrote:
> Imagine the following data type:
>
> data Person = Child { childAge :: Int, school :: School }
> | Adult { adultAge :: Int, job :: Job }
>
> Both the alternatives share an "age" field, but in order to access it we
> are obliged to match all the constructors:
>
> personAge :: Person -> Int
> personAge (Child {childAge = age}) = age
> personAge (Adult {adultAge = age}) = age
>
> Is there a way to define a common field in a data type (somehow like
> inheritance in the OOP world)?
Since you already have dedicated types for the school and the job, why not
have a descriptive name for the age as well so that you can drop the accessor
functions altogether? E.g.
type Age = Int
data Person = Child Age School
| Adult Age Job
If needed, you could of course still define
age :: Person -> Age
age (Child x _) = x
age (Adult x _) = x
but you may also find that you don't even need such a function in the first
place, pattern matching may do the job just fine:
mayRideRollerCoaster :: Person -> Bool
mayRideRollerCoaster (Child age _) = age > 12
mayRideRollerCoaster _ = True
--
Frerich Raabe - [email protected]
www.froglogic.com - Multi-Platform GUI Testing
------------------------------
Message: 2
Date: Tue, 29 Apr 2014 09:07:17 -0400
From: Michael Orlitzky <[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
On 04/28/2014 02:26 PM, Lorenzo Tabacchini wrote:
>
> Would it make sense to have a GHC extension (or even to make a Template
> Haskell hack) for this feature?
>
http://www.well-typed.com/blog/84/
------------------------------
Message: 3
Date: Tue, 29 Apr 2014 00:35:14 +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"
> http://www.well-typed.com/blog/84/ <http://www.well-typed.com/blog/84/>
Thank you! It's the kind of solution I was looking for.
Apparently I'll have to wait for GHC 7.10.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140429/b65347f2/attachment-0001.html>
------------------------------
Message: 4
Date: Tue, 29 Apr 2014 02:32:38 +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
If you could have a single polymorphic "age" function for all types
having an age, you could never have this runtime error, because the
compiler would infer which "age" we are referring to.
The GHC OverloadedRecordFields extension that Michael linked seems to do
what I am looking for (http://www.well-typed.com/blog/84/).
------------------------------
Message: 5
Date: Tue, 29 Apr 2014 15:55:43 +0000
From: Benjamin Edwards <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Type constructors sharing a common
field
Message-ID:
<can6k4ngw2hddafonzhjcuku70gdntvuf50bnfkf3gef_-j5...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Tue Apr 29 2014 at 16:42:40, Lorenzo Tabacchini
[email protected]<http://mailto:[email protected]>wrote:
If you could have a single polymorphic "age" function for all types
> having an age, you could never have this runtime error, because the
> compiler would infer which "age" we are referring to.
> The GHC OverloadedRecordFields extension that Michael linked seems to do
> what I am looking for (http://www.well-typed.com/blog/84/).
>
This is accurate. In the meantime avoid partiality as much as possible. If
you must have an age accessor, better to define the lens explicitly.
module Main where
import Control.Applicativeimport Control.Lens
main :: IO ()main = let p = Child 10
in print $ p ^. age
data Person = Child Int | Adult Int
age :: Lens' Person Intage k (Child x) = Child <$> k xage k (Adult x)
= Adult <$> k x
Yeah it?s boilerplate. You could makeLenses and then not export the
automatically generated selector functions.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140429/9d8960f6/attachment-0001.html>
------------------------------
Message: 6
Date: Tue, 29 Apr 2014 19:12:10 +0200
From: Chadda? Fouch? <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] development workflow ?
Message-ID:
<canfjzraofa54bfjrzas0tqxoqps2jrdwh2h-zsudcju4r9s...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Fri, Apr 25, 2014 at 4:41 PM, John M. Dlugosz
<[email protected]>wrote:
> If you're working on a Haskell project that includes packages, and the
> packages are in subdirectories of the source tree, how do you "build"?
>
> In my case, I want to alter the "gloss" package so I unpacked it, changed
> the name to "customgloss" in the .cabal file, and installed. Meanwhile, I
> used the package-quallified import GHC feature.
>
>
While that's not the question you asked, I note that you unpacked gloss
which probably means "cabal unpack gloss" (?). This is in general a
terrible idea because the latest released version may not be up to the
development version and if you want to work sanely, you'll have to put this
code in revision control, and you won't use the same as the author and so
on... So when you send a patch he may not be able to simply apply it to his
latest version and then it'll sit forgotten in his mail box and your work
will be lost for the community (ok, I may be overdoing it here...).
So the sane alternative is to check on the hackage page if a repository is
specified, like here : "git clone https://github.com/benl23x5/gloss" will
get you the latest and greatest, already in revision control and facilitate
the creation of a pull request in the future (in fact if you have a github
account, it's even better to go to this page and fork his repo to have your
own version on github).
--
Jeda?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140429/957eda00/attachment-0001.html>
------------------------------
Message: 7
Date: Tue, 29 Apr 2014 12:12:15 -0600
From: Dimitri DeFigueiredo <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Functors in Haskell
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
Hi All,
I'm trying to merge in my head the concepts of:
- functors from category theory; with,
- the Functor typeclass in haskell.
Here's what I have come up with:
A Functor F in haskell is a type constructor that provides a functor map
(fmap) and that maps Hask (the category of haskell types) into a
category generated by the Functor. For example, Maybe maps the category
of all haskell types "a" (i.e. Hask) into the category of all types of
the form "Maybe a" by providing an implementation of fmap.
Neglecting the fact that apparently Hask isn't a category, does this
sound reasonable? I think the insight for me here is that functors in
haskell are type constructors mapping Hask into another category. Is
that a good way to think about it?
Thanks!
Dimitri
------------------------------
Message: 8
Date: Tue, 29 Apr 2014 11:35:30 -0700
From: Rein Henrichs <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Functors in Haskell
Message-ID:
<cajp6g8x8pda7fek_xt550zo1c4eoiqc+ne_yazt7krjamil...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Yes, this is reasonable, but it might be useful to be a bit more explicit
about the categories involved.
An instance of Functor is a functor which maps objects and arrows in the
category of Hask (of Haskell types and functions) to... objects and arrows
in the category of Hask. It is an endofunctor. The object mapping must map
a type to a type and therefore must have the kind * -> *. This means that
it is a type constructor, e.g., Maybe. The arrow mapping must map arrows to
arrows, which means it must map functions to functions. fmap provides this
mapping and the Functor laws in Haskell are of course equivalent to the
laws from category theory.
And while the inclusion of bottom is problematic for Hask, it is still
possible to reason about it in a "morally correct" way (
http://www.cse.chalmers.se/~nad/publications/danielsson-et-al-popl2006.pdf).
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140429/6487c0e2/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 70, Issue 52
*****************************************