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:  Re: randomize the order of a list (John Dorsey)
   2.  List Sorting and I/O (Lorenzo Isella)
   3. Re:  List Sorting and I/O (Daniel Fischer)
   4. Re:  Haskell for POS (business) apps (David Virebayre)
   5. Re:  Haskell for POS (business) apps (David Virebayre)
   6. Re:  Haskell for POS (business) apps (Giuseppe Luigi Punzi)
   7. Re:  Haskell for POS (business) apps (David Virebayre)
   8.  how to implement accesor function for given data type
      (Martin Tomko)
   9.  Selecting Arguments in Function to Feed Map (Lorenzo Isella)


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

Message: 1
Date: Sun, 12 Sep 2010 14:43:15 -0400
From: John Dorsey <[email protected]>
Subject: Re: [Haskell-beginners] Re: randomize the order of a list
To: [email protected]
Cc: Heinrich Apfelmus <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Heinrich Apfelmus wrote:

> Why should it be uniform just because it looks nice? Looks can be
> deceiving, you need a mathematical proof to be certain.

My claim was that it is "uniform and simple"; naturally neither follows from
the other, but each has merit.

> Embarrassingly, the analysis in my previous message is wrong, though.
> Here an actually correct assessment of the algorithm. Or rather, of the
> two algorithms; the results are different depending on whether you use a
> pivot *element* or just a pivot *position*. It will turn out that the
> former is not uniform, while, to my surprise, the latter is uniform!

And this was my point.  I never considered a pivot *element*, which you
correctly point out wouldn't work so well.  I was referring to a pivot taken
from a randomly chosen *position*.  On re-reading Gabriel Scherer's original
musing:

>>>> Thanks for the link apfelmus, it's fairly interesting. The key to
>>>> making it work is the weighting of lists during merging based on their
>>>> lengths. I wonder if other sort algorithm can be adapted in such a
>>>> way, while preserving uniformity. Quicksort for example : is it enough
>>>> to choose the result position of the pivot randomly, and then placing
>>>> elements on either side with a probability of 1/2 ?

I may have misunderstood his original intent, as he refers to a random
"result position" for a pivot (chosen how?).  But if that's changed to
choosing the pivot from a random position, then it works out nicely.  I
think you agree with this later in your email.

And finally, re-reading your earlier comment:

>>> First, you can skip choosing the pivot position because it is already 
>>>  entailed by the choices of elements left and right to it.

I think I understand now what you were referring to... (redundantly)
choosing the destination for a pivot chosen by some other unspecified means.

It seems we were talking beside each other; I'm sorry if I misunderstood
you earlier.

Cheers,
John Dorsey



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

Message: 2
Date: Mon, 13 Sep 2010 00:59:40 +0200
From: Lorenzo Isella <[email protected]>
Subject: [Haskell-beginners] List Sorting and I/O
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Dear All,
Thanks to the help I got from the list, I was able to (almost) finish a 
script that performs some data postprocessing (and the code is really 
amazingly short).
Now, there are a few things left.
Consider the lists

bs = [4,5,3,1,5,2,7,2,8,2,2,3,3,5,6,7] and
ms = [2,2,2,2,4,4,4,4,6,6,4,4,4,10,12,14]

Now, I would like to sort bs (and that is easy) and then (since there is 
a 1-1 correspondence between the elements in ms and bs) re-order the 
elements in ms accordingly i.e. bs would become
  [1,2,2,2,2,3,3,3,4,5,5,5,6,7,7,8]
and ms [2,4,4,6,4,2,4,4,2,2,4,10,12,4,14].
How can I achieve that?
Finally, I would like to be able to save the two lists as plain text 
files (no commas, no brackets).
I tried writeFile+Show, but this saves the lists exactly as printed on 
screen (whereas I simply would like a text file showing a column of 
numbers when opened by your favorite editor).
Many thanks

Lorenzo


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

Message: 3
Date: Mon, 13 Sep 2010 01:24:17 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] List Sorting and I/O
To: [email protected]
Cc: Lorenzo Isella <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="iso-8859-1"

On Monday 13 September 2010 00:59:40, Lorenzo Isella wrote:
> Dear All,
> Thanks to the help I got from the list, I was able to (almost) finish a
> script that performs some data postprocessing (and the code is really
> amazingly short).
> Now, there are a few things left.
> Consider the lists
>
> bs = [4,5,3,1,5,2,7,2,8,2,2,3,3,5,6,7] and
> ms = [2,2,2,2,4,4,4,4,6,6,4,4,4,10,12,14]
>
> Now, I would like to sort bs (and that is easy) and then (since there is
> a 1-1 correspondence between the elements in ms and bs) re-order the
> elements in ms accordingly i.e. bs would become
>   [1,2,2,2,2,3,3,3,4,5,5,5,6,7,7,8]
> and ms [2,4,4,6,4,2,4,4,2,2,4,10,12,4,14].
> How can I achieve that?

import Data.Ord (comparing)
import Data.List

foo bs ms = unzip . sortBy (comparing fst) $ zip bs ms

> Finally, I would like to be able to save the two lists as plain text
> files (no commas, no brackets).
> I tried writeFile+Show, but this saves the lists exactly as printed on
> screen (whereas I simply would like a text file showing a column of
> numbers when opened by your favorite editor).
> Many thanks

One list as a column:

writeFile "bar" $ unlines (map show list)

A list as a space-separated sequence of numbers on one line:

writeFile "bar" $ unwords (map show list)

If you want to output the list elements in a fixed format (fixed width, 
right justified; rounded to k decimal places), take a look at Text.Printf.

If you want to output several lists as columns side by side, Text.Printf is 
also what you'd be looking for.

>
> Lorenzo


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

Message: 4
Date: Mon, 13 Sep 2010 10:54:15 +0200
From: David Virebayre <[email protected]>
Subject: Re: [Haskell-beginners] Haskell for POS (business) apps
To: [email protected]
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

2010/9/12  <[email protected]>:

> For the moment, We are developing a POS system. The first prototype is
> beeing developed under Windev(1), but, I would like to move to opensource

I have developped a POS system under Windev. Developping in Haskell
for this project was unfortunately not an option for me; however maybe
I can help you with a few answers :

- There are libraries for database access, for example HDBC or Takusen.
  I have used HDBC-mysql with no problems so far

- We accessed a serial display, a ticket printer and a cash drawer using
  OPOS drivers which are unfortunately a Windows only thing. I don't think
  there's an OPOS binding for Haskell, so you're left with two options:
  * develop such a binding yourself,
  * find a way to access the devices directly.

- There's no problem to code web services in Haskell.
  There's many networking libraries, web frameworks, etc.

- Windev has many shortcomings especially compared to Haskell, but one
  thing it's good at, is quickly doing user interfaces. In Haskell, the
  UI will IMHO require more work in Haskell. That being said, I've
  never designed large UIs in Haskell, so maybe with experience it


> Then, my main question is: I know (suppose), with Haskell you can develop
> whath you want, and I readed Scala is a good option, but I don't like the
> idea of depend of JVM, and Haskell do native executables. Is worth the
> effort for this type of applications? There are libs for this things? It's
> easy to maintain large projects?
>
> Sorry for my english and lack of knowledge :S
>
> PD: I come from a Delphi and Smalltalk background.
>
>
> (1)http://www.windev.com
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>


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

Message: 5
Date: Mon, 13 Sep 2010 10:55:34 +0200
From: David Virebayre <[email protected]>
Subject: Re: [Haskell-beginners] Haskell for POS (business) apps
To: [email protected]
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

Sorry, message sent by mistake, here's the end:

> - Windev has many shortcomings especially compared to Haskell, but one
>  thing it's good at, is quickly doing user interfaces. In Haskell, the
>  UI will IMHO require more work in Haskell. That being said, I've
>  never designed large UIs in Haskell, so maybe with experience it

... becomes easier/faster.

David.


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

Message: 6
Date: Mon, 13 Sep 2010 11:43:29 +0200
From: Giuseppe Luigi Punzi <[email protected]>
Subject: Re: [Haskell-beginners] Haskell for POS (business) apps
To: David Virebayre <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain;  charset="utf-8"

Hi David,

On Lunes 13 Septiembre 2010 10:54:15 usted escribió:
> 2010/9/12  <[email protected]>:
> > For the moment, We are developing a POS system. The first prototype is
> > beeing developed under Windev(1), but, I would like to move to opensource
> 
> I have developped a POS system under Windev. Developping in Haskell
> for this project was unfortunately not an option for me; however maybe

Why wasn't an option? What problems did you found?

> I can help you with a few answers :
> 
> - There are libraries for database access, for example HDBC or Takusen.
>   I have used HDBC-mysql with no problems so far
> 
> - We accessed a serial display, a ticket printer and a cash drawer using
>   OPOS drivers which are unfortunately a Windows only thing. I don't think
>   there's an OPOS binding for Haskell, so you're left with two options:
>   * develop such a binding yourself,
>   * find a way to access the devices directly.
> 
> - There's no problem to code web services in Haskell.
>   There's many networking libraries, web frameworks, etc.
> 

I will take a look...

> - Windev has many shortcomings especially compared to Haskell, but one
>   thing it's good at, is quickly doing user interfaces. In Haskell, the
>   UI will IMHO require more work in Haskell. That being said, I've
>   never designed large UIs in Haskell, so maybe with experience it
> 

Well, I like a lot Windev, Is very fast to get something usable and prototype, 
but:
1.- It forces me to develop from Windows.
2.- Is not fully cross-platform
3.- Bugfixes and improvements comes with new licenses (more money)

I need develop and deploy from/to Windows-Linux-Mac, and if possible, Android-
Windows Mobile..


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

Message: 7
Date: Mon, 13 Sep 2010 11:51:08 +0200
From: David Virebayre <[email protected]>
Subject: Re: [Haskell-beginners] Haskell for POS (business) apps
To: Giuseppe Luigi Punzi <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

2010/9/13 Giuseppe Luigi Punzi <[email protected]>:
> Hi David,
>
> On Lunes 13 Septiembre 2010 10:54:15 usted escribió:
>> 2010/9/12  <[email protected]>:
>> > For the moment, We are developing a POS system. The first prototype is
>> > beeing developed under Windev(1), but, I would like to move to opensource
>>
>> I have developped a POS system under Windev. Developping in Haskell
>> for this project was unfortunately not an option for me; however maybe
>
> Why wasn't an option? What problems did you found?

No problems at all, I was required by my hierarchy to do it in Windev
and had no say in that choice. The only way I can use Haskell at work
at the moment is for small stuff.

> Well, I like a lot Windev, Is very fast to get something usable and prototype,
> but:
> 1.- It forces me to develop from Windows.

My office box is under Linux, to develop with Windev I use virtualbox
( the dongle works fine )

> 2.- Is not fully cross-platform
> 3.- Bugfixes and improvements comes with new licenses (more money)

To that, add that the source code management system makes me cry.

David.


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

Message: 8
Date: Mon, 13 Sep 2010 14:52:06 +0200
From: Martin Tomko <[email protected]>
Subject: [Haskell-beginners] how to implement accesor function for
        given data      type
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

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!

class Geoms a where
    getCoordinates :: a -> b

instance Geoms Geometry where
     getCoordinates (Point _ a) = a
     getCoordinates (Polygon _ a) = a

And I want to access the Coordinates for each given geometry. Note that 
I tried to define it using records:  say, Polygon 
{getID::FID,gcoords::[Coordinate]}, but the coords function failed to 
match, due to having different return types for Geometry.

Thank you very much,
Martin


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

Message: 9
Date: Mon, 13 Sep 2010 15:03:26 +0200
From: Lorenzo Isella <[email protected]>
Subject: [Haskell-beginners] Selecting Arguments in Function to Feed
        Map
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

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?

Lorenzo


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

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


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

Reply via email to