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:  How to show a record (Francesco Ariis)
   2. Re:  How to show a record (Julian Birch)
   3. Re:  How to show a record (martin)
   4.  Using Traversal as a kind of pointer (Elise Huard)
   5. Re:  Using Traversal as a kind of pointer (Daniel Trstenjak)


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

Message: 1
Date: Sun, 17 Aug 2014 14:57:18 +0200
From: Francesco Ariis <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] How to show a record
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

On Sun, Aug 17, 2014 at 12:08:57PM +0100, Karolis Velicka wrote:
> In that case, can you elaborate please? I don't see how this is different
> to making the record itself an instance if Show.

If by "no difference" you mean "equivalent output", I guess we can ditch
Haskell and write programs in Basic.

What Martin is asking for is how you could implement such a feature if
something like |deriving (Show)| weren't there.

On 17 Aug 2014 10:44, "martin" <[email protected]> wrote:
> Right, but this is merely a coincidence.
>
> What I wanted is a way to show a value of a record, where all fields are
> instances of Show.
>
> Haskell itself is able to do this (and it even figures out the accessors,
> which I am not even asking for).

Martin, as far as I know this is not possible in standard ^Haskell 2010^ [1].
To perform this kind of magic people use ^Template Haskell^ [2], which is,
in so many words, a meta programming extension for GHC; with it you can
handle and go-back-and-forth between Concrete Syntax and the Abstract Syntax
Tree.
Template Haskell isn't type safe and that goes "against the grain" of
Haskell-the-language itself, I suppose (for sure it goes against mine);
it is used in some popular libraries (e.g. lens, yesod).


[1] http://www.haskell.org/onlinereport/haskell2010/
[2] http://www.haskell.org/haskellwiki/Template_Haskell
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140817/b5bbac06/attachment-0001.sig>

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

Message: 2
Date: Sun, 17 Aug 2014 17:46:25 +0100
From: Julian Birch <[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 show a record
Message-ID:
        <CAB0TuzAE6i=qm64xz4n_nkfljxv8ep0aosgrng0nzap0dty...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I think what Martin is aiming at is heterogeneous collections.
http://www.haskell.org/haskellwiki/Heterogenous_collections

As you can see from the article, you can do "the same thing" to a bunch of
objects of different types, but you've still got to "pack" them explicitly
first.  So in this particular case the answer is that it's not worth the
effort.  This may seem ridiculous, but it turns out that Haskell's approach
gives you a lot of power in other areas.

Julian


On 17 August 2014 13:57, Francesco Ariis <[email protected]> wrote:

> On Sun, Aug 17, 2014 at 12:08:57PM +0100, Karolis Velicka wrote:
> > In that case, can you elaborate please? I don't see how this is different
> > to making the record itself an instance if Show.
>
> If by "no difference" you mean "equivalent output", I guess we can ditch
> Haskell and write programs in Basic.
>
> What Martin is asking for is how you could implement such a feature if
> something like |deriving (Show)| weren't there.
>
> On 17 Aug 2014 10:44, "martin" <[email protected]> wrote:
> > Right, but this is merely a coincidence.
> >
> > What I wanted is a way to show a value of a record, where all fields are
> > instances of Show.
> >
> > Haskell itself is able to do this (and it even figures out the accessors,
> > which I am not even asking for).
>
> Martin, as far as I know this is not possible in standard ^Haskell 2010^
> [1].
> To perform this kind of magic people use ^Template Haskell^ [2], which is,
> in so many words, a meta programming extension for GHC; with it you can
> handle and go-back-and-forth between Concrete Syntax and the Abstract
> Syntax
> Tree.
> Template Haskell isn't type safe and that goes "against the grain" of
> Haskell-the-language itself, I suppose (for sure it goes against mine);
> it is used in some popular libraries (e.g. lens, yesod).
>
>
> [1] http://www.haskell.org/onlinereport/haskell2010/
> [2] http://www.haskell.org/haskellwiki/Template_Haskell
>
> _______________________________________________
> 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/20140817/ae6ceba0/attachment-0001.html>

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

Message: 3
Date: Sun, 17 Aug 2014 23:33:41 +0200
From: martin <[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 show a record
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Am 08/17/2014 06:46 PM, schrieb Julian Birch:
> I think what Martin is aiming at is heterogeneous collections.  
> http://www.haskell.org/haskellwiki/Heterogenous_collections
> 
> As you can see from the article, you can do "the same thing" to a bunch of 
> objects of different types, but you've still
> got to "pack" them explicitly first.  So in this particular case the answer 
> is that it's not worth the effort.  This may
> seem ridiculous, but it turns out that Haskell's approach gives you a lot of 
> power in other areas.
> 
> Julian
> 
> 
> On 17 August 2014 13:57, Francesco Ariis <[email protected] 
> <mailto:[email protected]>> wrote:
> 
>     On Sun, Aug 17, 2014 at 12:08:57PM +0100, Karolis Velicka wrote:
>     > In that case, can you elaborate please? I don't see how this is 
> different
>     > to making the record itself an instance if Show.
> 
>     If by "no difference" you mean "equivalent output", I guess we can ditch
>     Haskell and write programs in Basic.
> 
>     What Martin is asking for is how you could implement such a feature if
>     something like |deriving (Show)| weren't there.

Thanks for pointing out Heterogenous_collections to me.


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

Message: 4
Date: Mon, 18 Aug 2014 13:09:11 +0200
From: Elise Huard <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Using Traversal as a kind of pointer
Message-ID:
        <CAHfyCqmL5e69n-QD=ijoib05tge+keqvvdeqxjemozy6v5j...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Hi,

I'm programming a small game - amongst my types I have a 'world' structure
data World = World Background [Lifeform]
I'm calculating collisions between my player and the lifeforms, and
I'll need this result both to allow some actions and to modify the
world as a result.
I'm using FRP with elerea, so everything is defined as behaviours
(signals), and the collision signal is used in the signal accounting
of life spent and in the world signal.
I was thinking of returning a Traversal on the lifeforms that are
colliding so that I can both access the lifeforms concerned (when
performing actions and life accounting) and modify them as a result
(for the world).
Does that sound reasonable as a use of lenses?  Overengineered? Better
solutions?
Thank you,

Elise Huard


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

Message: 5
Date: Mon, 18 Aug 2014 13:30:05 +0200
From: Daniel Trstenjak <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Using Traversal as a kind of pointer
Message-ID: <20140818113005.GA2735@machine>
Content-Type: text/plain; charset=us-ascii


Hi Elise,

I'm not quite sure if I completely understood your use case, but if
you only want to modify the lifeforms that are colliding with the player,
then you could have something like:

   world & liveforms . filtered (collidingWith player) %~ \liveform -> ...

with

   liveforms :: Lens' World [Lifeform]

   collidingWith :: Player -> Lifeform -> Bool


I would consider this as a quite nice solution.


Greetings,
Daniel


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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 74, Issue 14
*****************************************

Reply via email to