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:  Selecting Arguments in Function to Feed Map (Magnus Therning)
   2. Re:  how to implement accesor function for        given data type
      (Brent Yorgey)
   3. Re:  how to implement accesor function for        given data type
      (Brent Yorgey)
   4. Re:  Selecting Arguments in Function to Feed Map
      (Alex Rozenshteyn)
   5. Re:  Selecting Arguments in Function to Feed Map
      (Tommy M. McGuire)
   6. Re:  Selecting Arguments in Function to Feed Map (Ozgur Akgun)


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

Message: 1
Date: Mon, 13 Sep 2010 14:16:36 +0100
From: Magnus Therning <[email protected]>
Subject: Re: [Haskell-beginners] Selecting Arguments in Function to
        Feed Map
To: Lorenzo Isella <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Mon, Sep 13, 2010 at 14:03, Lorenzo Isella <[email protected]> wrote:
> Dear All,
> Suppose you have the function
>
> f x y z = x*y +z
>
> and that you want to iterate it on a list
> z=[1,2,3,4], with
> x=4 and y=3
>
> then you would do the following
>
> map (f x y) z.
>
> Now consider the case in which the list is given by y e.g.
>
> y=[1,2,3,4], with
> x=4 and z=3.
>
> How can you iterate f on y (i.e. its second argument) while keeping x and y
> fixed?

Using a lambda expression (anonymous function) or through clever use of flip.

/M

-- 
Magnus Therning                        (OpenPGP: 0xAB4DFBA4)
magnus@therning.org          Jabber: magnus@therning.org
http://therning.org/magnus         identi.ca|twitter: magthe


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

Message: 2
Date: Mon, 13 Sep 2010 09:53:21 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] how to implement accesor function for
        given data type
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Mon, Sep 13, 2010 at 02:52:06PM +0200, Martin Tomko wrote:
> Dear all,
> apologies for a newbie question, but I am returning to Haskell after
> years of hiatus and Java...
> 
> I have the following data type (representing geometries):
> 
> data Geometry = Point FID Coordinate
>         | LineSegment FID (Coordinate,Coordinate)
>         | Polyline FID [Coordinate]
>         | Polygon FID [Coordinate]
>         deriving (Show,Eq)
> 
> type Coordinate = (Float, Float)
> 
> And this is where I fail: I have no idea how to type getCoordinates,
> in order to match against the three different combinations -> it can
> result into a Coordinate, or a typle, or a List. I am sure it is
> possible!

It is not possible.  What would you do with the coordinates once you
had them?  You wouldn't know what type of coordinates you would be
getting and hence you would be unable to do anything with them.

Why not something like this?

getCoordinates :: Geometry -> [Coordinate]
getCoordinates (Point _ c)             = [c]
getCoordinates (LineSegment _ (c1,c2)) = [c1,c2]
getCoordinates (Polyline _ cs)         = cs
getCoordinates (Polygon _ cs)          = cs

-Brent


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

Message: 3
Date: Mon, 13 Sep 2010 09:59:20 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] how to implement accesor function for
        given data type
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Mon, Sep 13, 2010 at 09:53:21AM -0400, Brent Yorgey wrote:
> On Mon, Sep 13, 2010 at 02:52:06PM +0200, Martin Tomko wrote:
> > Dear all,
> > apologies for a newbie question, but I am returning to Haskell after
> > years of hiatus and Java...
> > 
> > I have the following data type (representing geometries):
> > 
> > data Geometry = Point FID Coordinate
> >         | LineSegment FID (Coordinate,Coordinate)
> >         | Polyline FID [Coordinate]
> >         | Polygon FID [Coordinate]
> >         deriving (Show,Eq)
> > 
> > type Coordinate = (Float, Float)
> > 
> > And this is where I fail: I have no idea how to type getCoordinates,
> > in order to match against the three different combinations -> it can
> > result into a Coordinate, or a typle, or a List. I am sure it is
> > possible!

Another thought: if it is important to be able to tell which sort of
coordinates you have (single, pair, or list), you can make a new data
type, like this:

  data CoordinateSet = Single Coordinate
                     | Pair (Coordinate, Coordinate)
                     | List [Coordinate]

Now it should be no problem to write

  getCoordinates :: Geometry -> CoordinateSet

-Brent


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

Message: 4
Date: Mon, 13 Sep 2010 10:01:26 -0400
From: Alex Rozenshteyn <[email protected]>
Subject: Re: [Haskell-beginners] Selecting Arguments in Function to
        Feed Map
To: Magnus Therning <[email protected]>
Cc: Lorenzo Isella <[email protected]>, [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="utf-8"

To actually give the example:

> -- assuming that x and z are defined, and ys is the list
> map (\y -> f x y z) ys

On Mon, Sep 13, 2010 at 9:16 AM, Magnus Therning <[email protected]>wrote:

> On Mon, Sep 13, 2010 at 14:03, Lorenzo Isella <[email protected]>
> wrote:
> > Dear All,
> > Suppose you have the function
> >
> > f x y z = x*y +z
> >
> > and that you want to iterate it on a list
> > z=[1,2,3,4], with
> > x=4 and y=3
> >
> > then you would do the following
> >
> > map (f x y) z.
> >
> > Now consider the case in which the list is given by y e.g.
> >
> > y=[1,2,3,4], with
> > x=4 and z=3.
> >
> > How can you iterate f on y (i.e. its second argument) while keeping x and
> y
> > fixed?
>
> Using a lambda expression (anonymous function) or through clever use of
> flip.
>
> /M
>
> --
> Magnus Therning                        (OpenPGP: 0xAB4DFBA4)
> magnus@therning.org          Jabber: magnus@therning.org
> http://therning.org/magnus         identi.ca|twitter: magthe
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



-- 
          Alex R
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100913/bc84fa9a/attachment-0001.html

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

Message: 5
Date: Mon, 13 Sep 2010 10:33:50 -0500
From: "Tommy M. McGuire" <[email protected]>
Subject: Re: [Haskell-beginners] Selecting Arguments in Function to
        Feed Map
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

And to finish the example, fully parenthesized:

Prelude> let x = 4
Prelude> let y = [1,2,3,4]
Prelude> let z = 3
Prelude> map ((flip (f x)) z) y
[7,11,15,19]

I.e., apply f to x, flip the arguments, apply z, and map the result across y.

On 09/13/2010 09:01 AM, Alex Rozenshteyn wrote:
> To actually give the example:
> 
>> -- assuming that x and z are defined, and ys is the list
>> map (\y -> f x y z) ys
> 
> On Mon, Sep 13, 2010 at 9:16 AM, Magnus Therning <[email protected]
> <mailto:[email protected]>> wrote:
> 
>     On Mon, Sep 13, 2010 at 14:03, Lorenzo Isella
>     <[email protected] <mailto:[email protected]>> wrote:
>     > Dear All,
>     > Suppose you have the function
>     >
>     > f x y z = x*y +z
>     >
>     > and that you want to iterate it on a list
>     > z=[1,2,3,4], with
>     > x=4 and y=3
>     >
>     > then you would do the following
>     >
>     > map (f x y) z.
>     >
>     > Now consider the case in which the list is given by y e.g.
>     >
>     > y=[1,2,3,4], with
>     > x=4 and z=3.
>     >
>     > How can you iterate f on y (i.e. its second argument) while
>     keeping x and y
>     > fixed?
> 
>     Using a lambda expression (anonymous function) or through clever use
>     of flip.
> 
>     /M
> 
>     --
>     Magnus Therning                        (OpenPGP: 0xAB4DFBA4)
>     magnus@therning.org          Jabber: magnus@therning.org
>     http://therning.org/magnus         identi.ca
>     <http://identi.ca>|twitter: magthe
>     _______________________________________________
>     Beginners mailing list
>     [email protected] <mailto:[email protected]>
>     http://www.haskell.org/mailman/listinfo/beginners
> 
> 
> 
> 
> -- 
>           Alex R
> 
> 
> 
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners


-- 
Tommy M. McGuire
[email protected]


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

Message: 6
Date: Mon, 13 Sep 2010 18:05:09 +0100
From: Ozgur Akgun <[email protected]>
Subject: Re: [Haskell-beginners] Selecting Arguments in Function to
        Feed Map
To: Haskell Beginners <[email protected]>
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="utf-8"

On 13 September 2010 14:03, Lorenzo Isella <[email protected]> wrote:

> How can you iterate f on y (i.e. its second argument) while keeping x and y
> fixed?
>

 On 13 September 2010 14:16, Magnus Therning <[email protected]> wrote:

> Using a lambda expression (anonymous function) or through clever use of
> flip.
>

 On 13 September 2010 15:01, Alex Rozenshteyn <[email protected]> wrote:

> To actually give the example:
>
[example with a lambda expression]


On 13 September 2010 16:33, Tommy M. McGuire <[email protected]> wrote:

> And to finish the example, fully parenthesized:
>
[example with a clever use of flip]


To conclude, Haskell is a great language and has a fantastic user community.

Ozgur Akgun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100913/303f25f3/attachment-0001.html

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

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


End of Beginners Digest, Vol 27, Issue 30
*****************************************

Reply via email to