[Haskell-cafe] Simulating OO programming with type classes; writing a factory fu nction

2005-06-01 Thread oleg

Alistair Bayley wrote:

 There's a small problem: how to write a factory function that returns values
 of various subtypes. The makeSubType function below won't compile, obviously
 because the returns types are different (they're not the same 'm').

Indeed, expressions in both branches of an `if' statement

   if s == SubBase1
   then SubBase1 3
   else SubBase2 (SubBase1 4)

must be of the same type. If we had intersection types (I'm not
complaining!), the compiler would have derived the intersection by
itself. As things are now, we have to make the intersection manually:
we have to abstract away irrelevant pieces. Expressions
`SubBase1 3' and `SubBase2 (SubBase1 4)' have in common the fact that
both have types that are instances of a Method class. So, we have to
write that common piece of information explicitly. There are two ways
of doing this, which can be called direct style and CPS style. In
direct style, we do

 data WM = forall m. Method m = WM m
 makeSubType1 :: String - WM 
 makeSubType1 s =
   if s == SubBase1
   then WM $ SubBase1 3
   else WM $ SubBase2 (SubBase1 4)

 test1 = let foo x = case x of WM y - method2 y
 in map (foo . makeSubType1) [SubBase1, SubBase2]

The CPS style is just the inverse:

 -- Higher-ranked type: signature is required!
 makeSubType2:: (forall m. Method m = m - w) - String - w
 makeSubType2 consumer s =
   if s == SubBase1
   then consumer $ SubBase1 3
   else consumer $ SubBase2 (SubBase1 4)

 test2 = let foo x = method2 x
   in map (makeSubType2 foo) [SubBase1, SubBase2]

The CPS style involves less tagging (no need to add and remove the tag
WM). Also, the CPS style is more general:

 makeSubType1' s = makeSubType2 WM s

 test3 = let foo x = case x of WM y - method2 y
   in map (foo . makeSubType1') [SubBase1, SubBase2]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Space questions about intern and sets

2005-06-01 Thread Marcin 'Qrczak' Kowalczyk
Gracjan Polak [EMAIL PROTECTED] writes:

 intern :: Ord a = a - a
 intern x = unsafePerformIO $ internIO x

 iorefset :: Ord a = IORef(Map.Map a a)
 iorefset = unsafePerformIO $ do
  newIORef $ Map.empty

It will not work because you can't put values of different types as
keys of the same dictionary, as you can't compare them.

-- 
   __( Marcin Kowalczyk
   \__/   [EMAIL PROTECTED]
^^ http://qrnik.knm.org.pl/~qrczak/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Type extensions

2005-06-01 Thread Thomas Davie

Hi,
  I was wondering if I hat missed something and it was possible to  
do this within the Haskell type system or not...


Essentially I would like some sort of inderritance property for  
Haskell types, I often find myself wanting to for example extend a  
tree with black/white colouring, or later extend the tree with some  
sort of ID, etc.


So I would eno up with three data types

data MyTree = Branch MyTree MyTree | Leaf

type BwTag = Bool
data MyBwTree = Branch BwTag MyBwTree MyBwTree | Node BwTag

data MyBwTaggedTree = Branch BwTag Int MyBwTaggedTree MyBwTaggedTree  
| Node BwTag Int


and several functions to move from one to another.  (Or define the  
most complex and not always use all the attrdbutes). What I would  
prefer is to be able to spocify something like:


data MyTree = Branch MyTree MyTree | Leaf

type BwTag = Bool
data MyBwTree extends MyTree with BwTag=True

data MyBwTaggedTree extends MyBwTree with Int=0

Specifying that myBwTree is the same as MyTree but with an extra  
argument on each node, and to generate functions to translate between  
them that fill in True as a default value for the extra tag.


Is this possible?

Thanks

Tom Davie

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Type extensions

2005-06-01 Thread Henning Thielemann

On Wed, 1 Jun 2005, Thomas Davie wrote:

 Hi,
I was wondering if I hat missed something and it was possible to
 do this within the Haskell type system or not...

 Essentially I would like some sort of inderritance property for
 Haskell types, I often find myself wanting to for example extend a
 tree with black/white colouring, or later extend the tree with some
 sort of ID, etc.

 So I would eno up with three data types

 data MyTree = Branch MyTree MyTree | Leaf

 type BwTag = Bool
 data MyBwTree = Branch BwTag MyBwTree MyBwTree | Node BwTag

What about

data MyTree a = Branch a (MyTree a) (MyTree a) | Node a

and the types
 MyTree ()
 MyTree Bool
 MyTree (Bool, Int)
 ?

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Type extensions

2005-06-01 Thread Thomas Davie


On 1 Jun 2005, at 15:54, Henning Thielemann wrote:



On Wed, 1 Jun 2005, Thomas Davie wrote:



Hi,
   I was wondering if I hat missed something and it was possible to
do this within the Haskell type system or not...

Essentially I would like some sort of inderritance property for
Haskell types, I often find myself wanting to for example extend a
tree with black/white colouring, or later extend the tree with some
sort of ID, etc.

So I would eno up with three data types

data MyTree = Branch MyTree MyTree | Leaf

type BwTag = Bool
data MyBwTree = Branch BwTag MyBwTree MyBwTree | Node BwTag



What about

data MyTree a = Branch a (MyTree a) (MyTree a) | Node a

and the types
 MyTree ()
 MyTree Bool
 MyTree (Bool, Int)
 ?
That's exactly what I would normally do, but my data type is in a  
library and is not parameterised.


Tom Davie
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Type extensions

2005-06-01 Thread Henning Thielemann

On Wed, 1 Jun 2005, Thomas Davie wrote:

 On 1 Jun 2005, at 15:54, Henning Thielemann wrote:

  What about
 
  data MyTree a = Branch a (MyTree a) (MyTree a) | Node a
 
  and the types
   MyTree ()
   MyTree Bool
   MyTree (Bool, Int)
   ?

 That's exactly what I would normally do, but my data type is in a
 library and is not parameterised.

Then it is the wrong library. :-)

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Wash broken with GHC 6.4

2005-06-01 Thread John Goerzen
Hi,

I'm trying to use Wash with GHC 6.4.  I have applied the patch from
http://article.gmane.org/gmane.comp.lang.haskell.libraries/3160, and now
it at least compiles.  However, despite using -package WASH -package
WASH-CGI -package WASHHTML, ghc is not automatically sending the
input files through wash2hs.  GHC 6.2 did this.

Incidentally, is Wash dead upstream?  I am surprised that there is no
upstream version yet that even tries to work with GHC 6.4.

-- John

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] CGI module almost useless

2005-06-01 Thread John Goerzen
My apologies if this sounds like a bit of a rant; I know people put good
effort into this, but

The Network.CGI module in fptools (and GHC) is not very useful.  I think
that it should be removed or re-tooled.  Here are the main problems with
it:

1. It does not permit custom generation of output headers.  Thus the CGI
script cannot do things like set cookies, manage HTTP auth, etc.

2. It does not permit generation of anything other than text/html
documents.  Many CGI scripts are used to manage other types of
documents.  Notably this makes it incompatible with serving up even
basic things like stylesheets and JPEGs.

3. It does not permit the use of any custom design to serve up HTML,
forcing *everything* to go through Text.Html.  This makes it impossible
to do things like serving up HTML files from disk.

4. There is documentation in the code, but it is as comments only, and
doesn't show up in the Haddock-generated GHC library reference.  (Should
be an easy fix)

5. It does not appear to support file uploads in any sane fashion

Is there a better CGI module out there somewhere that I'm missing, or
should I just set about writing my own?


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] CGI module almost useless

2005-06-01 Thread Jeremy Shaw
Hello,

I have done all of those things in WASH. But, don't let that stop you
from writing something better :) I think some people started a project
to write a CGI interface based on a 'Category' -- where a 'Category'
is like an 'Arrow' without the 'pure/arr' function...

Jeremy Shaw.

At Wed, 1 Jun 2005 17:44:38 + (UTC),
John Goerzen wrote:
 
 My apologies if this sounds like a bit of a rant; I know people put good
 effort into this, but
 
 The Network.CGI module in fptools (and GHC) is not very useful.  I think
 that it should be removed or re-tooled.  Here are the main problems with
 it:
 
 1. It does not permit custom generation of output headers.  Thus the CGI
 script cannot do things like set cookies, manage HTTP auth, etc.
 
 2. It does not permit generation of anything other than text/html
 documents.  Many CGI scripts are used to manage other types of
 documents.  Notably this makes it incompatible with serving up even
 basic things like stylesheets and JPEGs.
 
 3. It does not permit the use of any custom design to serve up HTML,
 forcing *everything* to go through Text.Html.  This makes it impossible
 to do things like serving up HTML files from disk.
 
 4. There is documentation in the code, but it is as comments only, and
 doesn't show up in the Haddock-generated GHC library reference.  (Should
 be an easy fix)
 
 5. It does not appear to support file uploads in any sane fashion
 
 Is there a better CGI module out there somewhere that I'm missing, or
 should I just set about writing my own?
 
 
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] re: Python

2005-06-01 Thread Bulat Ziganshin
Hello Stijn,

Tuesday, May 31, 2005, 2:36:07 PM, you wrote:
SDS Yes. Many people I know state the functional part as a big reason why
SDS they chose python.

are you know Ruby? :)  it has all the same stuff, including code
blocks, which can refer to variables from outer context

for example, arr.inject { |sum,a| sum+a } will count sum of all
elements in array arr

-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] CGI module almost useless

2005-06-01 Thread John Goerzen
On Wed, Jun 01, 2005 at 10:54:54AM -0700, Jeremy Shaw wrote:
 Hello,
 
 I have done all of those things in WASH. But, don't let that stop you
 from writing something better :) I think some people started a project
 to write a CGI interface based on a 'Category' -- where a 'Category'
 is like an 'Arrow' without the 'pure/arr' function...

From what I can tell, there are two problems with WASH:

1) Everything must be done the WASH way

2) WASH is mostly broken with GHC 6.4

Let me elaborate a bit on #1.

Let's say I have a CGI interface pre-defined; I take certain parameters
from a GET request and do certain things, generating certain headers no
the result.

WASH is all centered around generating its own forms, naming its own
fields, passing around its own state.  It's not at all clear how to
handle this myself, as I would with Perl or PHP.

If there is a way, please explain it and I'll be happy :-)

I think that the GHC 6.4 brokenness is fixable, but it makes me nervous
that upstream has said nothing about it to date.

-- John
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] CGI module almost useless

2005-06-01 Thread Niklas Broberg
Shameless plug warning.

 From what I can tell, there are two problems with WASH:
 
 1) Everything must be done the WASH way
 
 2) WASH is mostly broken with GHC 6.4
 
 Let me elaborate a bit on #1.
 
 Let's say I have a CGI interface pre-defined; I take certain parameters
 from a GET request and do certain things, generating certain headers no
 the result.
 
 WASH is all centered around generating its own forms, naming its own
 fields, passing around its own state.  It's not at all clear how to
 handle this myself, as I would with Perl or PHP.
 
 If there is a way, please explain it and I'll be happy :-)

Perhaps you want to have a look at HSP? :-)
It doesn't solve all your problems though; it still requires the
output to be text/html (or text/xhtml rather), but hopefullly a future
incarnation will be more general.

Anyway, you can get it from

http://www.cs.chalmers.se/~d00nibro/hsp

Feedback greatly appreciated. :-)

/Niklas
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


RE: [Haskell-cafe] CGI module almost useless

2005-06-01 Thread Conal Elliott
I'd like to hear more about people using Arrows-minus-arr, as I ran into
the same in a project I'm working on for interactive construction of
GUI-wrapped functional values  code.

- Conal

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jeremy Shaw
Sent: Wednesday, June 01, 2005 10:55 AM
To: John Goerzen
Cc: haskell-cafe@haskell.org
Subject: Re: [Haskell-cafe] CGI module almost useless

Hello,

I have done all of those things in WASH. But, don't let that stop you
from writing something better :) I think some people started a project
to write a CGI interface based on a 'Category' -- where a 'Category'
is like an 'Arrow' without the 'pure/arr' function...

Jeremy Shaw.

At Wed, 1 Jun 2005 17:44:38 + (UTC),
John Goerzen wrote:
 
 My apologies if this sounds like a bit of a rant; I know people put
good
 effort into this, but
 
 The Network.CGI module in fptools (and GHC) is not very useful.  I
think
 that it should be removed or re-tooled.  Here are the main problems
with
 it:
 
 1. It does not permit custom generation of output headers.  Thus the
CGI
 script cannot do things like set cookies, manage HTTP auth, etc.
 
 2. It does not permit generation of anything other than text/html
 documents.  Many CGI scripts are used to manage other types of
 documents.  Notably this makes it incompatible with serving up even
 basic things like stylesheets and JPEGs.
 
 3. It does not permit the use of any custom design to serve up HTML,
 forcing *everything* to go through Text.Html.  This makes it
impossible
 to do things like serving up HTML files from disk.
 
 4. There is documentation in the code, but it is as comments only, and
 doesn't show up in the Haddock-generated GHC library reference.
(Should
 be an easy fix)
 
 5. It does not appear to support file uploads in any sane fashion
 
 Is there a better CGI module out there somewhere that I'm missing, or
 should I just set about writing my own?
 
 
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] G machine in FORTH

2005-06-01 Thread Andrew Harris
Hi -

   Brace yourself... I work in an environment where FORTH is still used.

   I've been thinking about writing a G-machine interpreter in FORTH
so that one could write Haskell like programs that would compile down
and run graph-reduction style on the FORTH machine.

   Many developers think FORTH is nice, but the language is so, shall
we say, terse.

   I'm curious about what people think about this; having the
expressiveness of a Haskell-like language that compiles to this
environment might provide the best of both worlds, simple hardware
architecture and an advanced programming language.

let me know what you think,
-andrew
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] G machine in FORTH

2005-06-01 Thread karczma
Andrew Harris writes: 

   Brace yourself... I work in an environment where FORTH is still used. 


   I've been thinking about writing a G-machine interpreter in FORTH
so that one could write Haskell like programs that would compile down
and run graph-reduction style on the FORTH machine.



let me know what you think,


Nice. 


Just two questions. Does your FORTH has a decent memory management system,
permitting to implement GC? 


Do you have some idea how to modify the standard threading execution of
FORTH in order to have laziness? 

Jerzy Karczmarczuk 


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] G machine in FORTH

2005-06-01 Thread Krasimir Angelov
Actually I am very impressed from the FORTH simplicity and efficiency.
I was developing one FORTH system for DOS a couple of years ago and I
think it is very useful for small programs that have to perform low
level/hardware tasks. Unfortunatelly it doesn't scale well for larger
applications. I don't know how well it can be used as G-machine
interpreter but its execution model has a lot of common with STG
machine. In STG each closure has a header word which is a pointer to
its entry code. In FORTH each procedure has a header word which also
points to some entry code. The entry code receives the address of the
entered procedure in special (usually EBX on x86) register just like
in STG (where the used register is ESI). The execution of any FORTH
program is a sequence of jumps from one entry code to another just
like in STG. Of course STG is much more complicated because the
closures are dynamically allocated and there is a garbage collector
too. Thanks to its simple execution model I still think that FORTH is
the fastest interpreted language, just like STG is the fastest virtual
machine for Haskell.

Cheers,
  Krasimir

On 6/1/05, Andrew Harris [EMAIL PROTECTED] wrote:
 Hi -
 
   Brace yourself... I work in an environment where FORTH is still used.
 
   I've been thinking about writing a G-machine interpreter in FORTH
 so that one could write Haskell like programs that would compile down
 and run graph-reduction style on the FORTH machine.
 
   Many developers think FORTH is nice, but the language is so, shall
 we say, terse.
 
   I'm curious about what people think about this; having the
 expressiveness of a Haskell-like language that compiles to this
 environment might provide the best of both worlds, simple hardware
 architecture and an advanced programming language.
 
 let me know what you think,
 -andrew
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] G machine in FORTH

2005-06-01 Thread Michael Vanier

I always thought Forth was way cool, but I've never managed to get anything
significant written in it.  I think that Forth has echoes of the
point-free style in Haskell, but Haskell is a lot friendlier.

Is the Forth environment part of the hardware?  If your Forth is just a
threaded interpreter written in software then it seems wasteful to compile
Haskell down to an interpreted environment.  If it's part of the hardware
then I think it would be (at the very least) an interesting exercise.

Mike

 Date: Wed, 1 Jun 2005 17:25:24 -0400
 From: Andrew Harris [EMAIL PROTECTED]
 Reply-To: Andrew Harris [EMAIL PROTECTED]
 
 Hi -
 
Brace yourself... I work in an environment where FORTH is still used.
 
I've been thinking about writing a G-machine interpreter in FORTH
 so that one could write Haskell like programs that would compile down
 and run graph-reduction style on the FORTH machine.
 
Many developers think FORTH is nice, but the language is so, shall
 we say, terse.
 
I'm curious about what people think about this; having the
 expressiveness of a Haskell-like language that compiles to this
 environment might provide the best of both worlds, simple hardware
 architecture and an advanced programming language.
 
 let me know what you think,
 -andrew

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Type extensions

2005-06-01 Thread ajb
G'day all.

Quoting Thomas Davie [EMAIL PROTECTED]:

 Essentially I would like some sort of inderritance property for
 Haskell types, I often find myself wanting to for example extend a
 tree with black/white colouring, or later extend the tree with some
 sort of ID, etc.

Have you had a look at these?

http://haskell.org/hawiki?IndirectComposite
http://haskell.org/hawiki?DecoratingStructures

Cheers,
Andrew Bromage
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] G machine in FORTH

2005-06-01 Thread Dimitry Golubovsky

Andrew Harris wrote:


   I've been thinking about writing a G-machine interpreter in FORTH
so that one could write Haskell like programs that would compile down
and run graph-reduction style on the FORTH machine.

   Many developers think FORTH is nice, but the language is so, shall
we say, terse.

   I'm curious about what people think about this; having the
expressiveness of a Haskell-like language that compiles to this
environment might provide the best of both worlds, simple hardware
architecture and an advanced programming language.



IMHO Koopman's TIGRE (http://www.ece.cmu.edu/~koopman/tigre/) might be 
a close approximation of what you want.


I had some (rather non-serious) experience with Forth, and I had great 
pleasure reading Koopman's paper on TIGRE. Unfortunately I couldn't find 
any further development on this topic (although I saw some later 
Koopman's publications on Forth itself). I guess, only someone thinking 
Forth (as in the Brodie's book) might develop such a thing.


Dimitry Golubovsky
Middletown, CT


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe