Re: [Haskell-cafe] instance of String illegal

2006-09-29 Thread Stefan Holdermans

Adam,


class Foo a where
mkFoo :: a - String

instance Foo String where
mkFoo x = x


In addition to making use of language extensions or wrapper types,  
you could go with the following workaround in just plain Haskell 98:


  import List

  class MkFoo a where
mkFoo :: a - String

mkFooList :: [a] - String
mkFooList =  concat . intersperse ,  . map mkFoo

  instance MkFoo Char where
mkFoo = (: [])
mkFooList = concatMap mkFoo

  instance (MkFoo a) = MkFoo [a] where
mkFoo = mkFooList

For instance:

   mkFoo False
  no

   mkFoo [False, True]
  no, yes

   mkFoo 'h'
  h

   mkFoo haskell
  haskell

The same approach is taken for implementing Show in the standard  
libraries. Note that it requires you to fix the type constructors  
that are to be treated in a special manner ([] in the above example).


HTH,

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


RE: [Haskell-cafe] Optimizing a title matcher

2006-09-29 Thread Bayley, Alistair
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Bulat Ziganshin
 Sent: 28 September 2006 17:29
 To: Lyle Kopnicky
   
 now i will work on edit-distance algorithm. i'm have an idea of
 checking the real distance between chars - as on my keyboard, so for
 example sprry can be mistake for sorry, but not for serry


For English text, the Soundex algorithm (or one of its variations) might
do a good job of matching:

http://en.wikipedia.org/wiki/Soundex

Google doesn't show any Haskell implementations yet.

Alistair
*
Confidentiality Note: The information contained in this message,
and any attachments, may contain confidential and/or privileged
material. It is intended solely for the person(s) or entity to
which it is addressed. Any review, retransmission, dissemination,
or taking of any action in reliance upon this information by
persons or entities other than the intended recipient(s) is
prohibited. If you received this in error, please contact the
sender and delete the material from any computer.
*
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Haskell DLL crashes Excel

2006-09-29 Thread Cyril Schmidt
A few people recently asked how to pass a string between a Haskell DLL 
and Excel.
I attach the proof-of-concept code that I wrote a while ago; it 
demonstrates passing
a string from Excel to Haskell and the other way. Most of the C++ code 
is taken

from code examples at http://msdn.microsoft.com

Beware, though, that the code has never been thoroughly tested. I ran 
it, and it did not
crash -- that's almost all I can say. I even do not know if it leaks any 
memory. Use it

at your own peril.

The tar file contains a sample Excel sheet, and the sources of two DLLs: 
a COM DLL
which interfaces with Excel, and a Haskell DLL which is invoked by the 
COM DLL.

You will need Visual Studio 7.1 to build the COM DLL.

The Haskell DLL exports one function, hString2String, which takes a 
C-style string,

and returns the reverse of it.

To build the Haskell DLL, run build.bat.
To build (and register) the COM DLL, open Excel2Haskell.sln in Visual 
Studio, and hit Build.
Once the two libraries are built, open Worksheet.xls and see how the 
function is invoked.


Note that the COM DLL can be used not only by Excel, but by any other 
program or script that
understands COM. For example, VBA scripts in Word, or VB and Javascript 
run by Wscript or

Cscript.

Hope this helps.

Regards,

Cyril
___



Excel2Haskell.tar.bz2
Description: Binary data
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Computing lazy and strict list operations at the same time

2006-09-29 Thread Brandon Moore

Andrew Pimlott wrote:

This is a follow-up to a thread from June-July[1].  The question was how to
write the function

initlast :: [a] - ([a], a)
initlast xs = (init xs, last xs)

so that it can be consumed in fixed space:

main = print $ case initlast [0..10] of
 (init, last) - (length init, last)

Attempts were along the lines of

initlast :: [a] - ([a], a)
initlast [x]= ([], x)
initlast (x:xs) = let (init, last) = initlast xs
  in  (x:init, last)

I seemed obvious to me at first (and for a long while) that ghc should
force both computations in parallel; but finally at the hackathon
(thanks to Simon Marlow) I realized I was expecting magic:  The elements
of the pair are simply independent thunks, and there's no way to partly
force the second (ie, last) without forcing it all the way.

According to the stuff about selector thunks, it seems this should work

initlast [x] = ([],[x])
initlast (x:xs) =
let ~(init,last) = initlast xs
in (x:init, last)

It does, at least when I build with -ddump-simpl. Other builds, I get a 
program that overflows. Attached is a heap profile for a run with the 
main (10M rather than 100M as above - that just takes too long)


main = print $ case initlast [0..1]
of (init, last) - (length init, last)

Brandon


a.out.ps
Description: PostScript document
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] existential types (was Re: Optimization problem)

2006-09-29 Thread Ross Paterson
On Thu, Sep 28, 2006 at 03:22:25PM +0100, Simon Peyton-Jones wrote:
 | Does anything go wrong with irrefutable patterns for existential types?
 
 Try giving the translation into System F.

I'm a bit puzzled about this.  A declaration

data Foo = forall a. MkFoo a (a - Bool)

is equivalent to

newtype Foo = forall a. Foo (Foo' a)
data Foo' a = MkFoo a (a - Bool)

except that you also don't allow existentials with newtypes, for
similarly unclear reasons.  If you did allow them, you'd certainly
allow this equivalent of the original irrefutable match:

... case x of
Foo y - let MkFoo val fn = y in fn val

So, is there some real issue with existentials and non-termination?

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


Re: [Haskell-cafe] Re: A better syntax for qualified operators?

2006-09-29 Thread Brian Hulley

Benjamin Franksen wrote:

Brian Hulley wrote:

ith = Data.Array.IArray.(!)


Sorry, but I can't see the problem here. Why can't the editor offer
the operator as '!' in the list of options, and if the user selects
it insert both '(' and ')' at the right places (i.e. before the
module name and after the operator)? Is there some unwritten law that
forbids editors or IDEs to insert stuff at positions other than the
current cursor position?


I hadn't thought of that - I've now decided to just use the existing syntax 
here.




Generally speaking, I would always hesitate to change the language so
it better suits programming tools(*). It is the tools which should
adapt to the language, even if that means the programmer has to find
new ways of suporting the user (and the language). The most important
reason being that code is more often read than written.


My motivation for the change was that it would better suit the human user of 
the programming tool, though in this particular instance you and Henning 
have convinced me that the original syntax was better after all.




At the danger of becoming completely off-topic now (sorry!), I have
to say that I find /both/ versions ugly and unnecessarily hard to
read. My personal solution is to generally avoid qualified imports.


How does this solution scale? Surely it's only lucky if people happen to 
choose names that don't clash with those of other modules?



I use it only if absolutely necessary to disambiguate some symbol, and
then just for that symbol. I am aware that there is an opposing
faction here, who tries to convinve everyone that qualified import
should be the standard (and the actual exported symbols --at least
some of them-- meaningless, such as 'C' or 'T').


Although C and T are in themselves meaningless, the name of the module 
itself is not. As I understand it, this convention makes the module name 
carry the meaning so you use Set.T instead of Set.Set where the meaning is 
duplicated (a rather uneasy situation) in both the module name and type 
name.



I think such a
convention is inappropriate for a functional language (especially one
with user defined operators). There simply is no natural 1:1
correspondence between data type declaration and functions acting on
that data built into the language, as opposed to e.g. OO languages.
Extensibility in the functional dimension, i.e. the ability to
arbitrarily add functions that operate on some data without having to
change the code (module) that defines the data, is one of the
hallmarks of functional programming, as opposed to OO
programming.


If you have an abstract data type then it *is* like an object (though in a 
potentially more powerful way than in OOP) because there is no other way to 
manipulate values of that type.
If the type is not abstract, the advantage of calling it T is just that it 
avoids naming it twice (by type name and module name) in the situation where 
you want to not worry about name clashes with constructors of other types.



However, nothing prevents us from offering two
interfaces (visible modules), one where the data type is abstract (client
interface) and a different one where it is concrete (extension
interface)


You can still call both types T... :-)

Regards, Brian.
--
Logic empowers us and Love gives us purpose.
Yet still phantoms restless for eras long past,
congealed in the present in unthought forms,
strive mightily unseen to destroy us.

http://www.metamilk.com 


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


RE: [Haskell-cafe] existential types (was Re: Optimization problem)

2006-09-29 Thread Simon Peyton-Jones
I must be missing your point.  Newtype is just type isomorphism; a new
name for an existing type.  But there is not existing type exists x.
T(x).  So it's not surprising that newtype doesn't support
existentials.

I've lost track of this thread.  Can you re-state the question?  I'm
strongly influence by the question can we translate this into System F
+ (existential) data types because (a) that's what GHC does (b) it's an
excellent sanity check.  E.g. if you can, then we know the system is
sound.

Simon

| -Original Message-
| From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Ross
| Paterson
| Sent: 29 September 2006 10:37
| To: haskell-cafe@haskell.org
| Subject: [Haskell-cafe] existential types (was Re: Optimization
problem)
| 
| On Thu, Sep 28, 2006 at 03:22:25PM +0100, Simon Peyton-Jones wrote:
|  | Does anything go wrong with irrefutable patterns for existential
types?
| 
|  Try giving the translation into System F.
| 
| I'm a bit puzzled about this.  A declaration
| 
|   data Foo = forall a. MkFoo a (a - Bool)
| 
| is equivalent to
| 
|   newtype Foo = forall a. Foo (Foo' a)
|   data Foo' a = MkFoo a (a - Bool)
| 
| except that you also don't allow existentials with newtypes, for
| similarly unclear reasons.  If you did allow them, you'd certainly
| allow this equivalent of the original irrefutable match:
| 
|   ... case x of
|   Foo y - let MkFoo val fn = y in fn val
| 
| So, is there some real issue with existentials and non-termination?
| 
| ___
| 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] existential types (was Re: Optimization problem)

2006-09-29 Thread Ross Paterson
On Fri, Sep 29, 2006 at 11:19:26AM +0100, Simon Peyton-Jones wrote:
 I must be missing your point.  Newtype is just type isomorphism; a new
 name for an existing type.  But there is not existing type exists x.
 T(x).  So it's not surprising that newtype doesn't support
 existentials.

And yet newtype does support recursion.

 I've lost track of this thread.

The story so far:
apfelmus: why are there no irrefutable patterns for GADTs?
Conor: because you could use them to write unsafeCoerce
Ross: how about irrefutable patterns (or newtypes) for existential types?
Simon: Try giving the translation into System F + (existential) data types

Copying a notion of datatype from Haskell to Core and then asking for
a translation to that seems to be begging the question.  If your target
really was System F, you could use the standard encoding of existentials
as nested foralls, but there's the problem that Haskell function spaces
differ from System F ones, System F is strongly normalizing, etc.

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


[Haskell-cafe] irrefutable patterns for existential types / GADTs

2006-09-29 Thread apfelmus
Ross Paterson wrote:
 The story so far:
 apfelmus: why are there no irrefutable patterns for GADTs?
 Conor: because you could use them to write unsafeCoerce
 Ross: how about irrefutable patterns (or newtypes) for existential types?
 Simon: Try giving the translation into System F + (existential) data types

I'd like to add that I see no problem with

   coerce :: Eq a b - a - b
   coerce ~Refl x = x

as long as we have

   coerce _|_ x === _|_

The wish is that

   f = \refl - Just . coerce refl
 = \~Refl x - Just x

should satisfy

   f _|_ x === Just _|_
   f _|_ x =/= _|_

and likewise for any other constructor than Just.

Regards,
apfelmus

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


Re: [Haskell-cafe] irrefutable patterns for existential types / GADTs

2006-09-29 Thread Conor McBride

[EMAIL PROTECTED] wrote:

Ross Paterson wrote:
  

The story so far:
apfelmus: why are there no irrefutable patterns for GADTs?
Conor: because you could use them to write unsafeCoerce
Ross: how about irrefutable patterns (or newtypes) for existential types?
Simon: Try giving the translation into System F + (existential) data types



I'd like to add that I see no problem with

   coerce :: Eq a b - a - b
   coerce ~Refl x = x

as long as we have

   coerce _|_ x === _|_
  


But that makes it refutable! For the above, either

 coerce _|_ x === x

or the notation is being abused.

The trouble is that GADT pattern matching has an impact on types, as 
well as being a selector-destructor mechanism, and for the impact on 
types to be safe, the match must be strict.


For existentials, I'm not sure, but it seems to me that there's not such 
a serious issue. Isn't the only way you can use the type which allegedly 
exists to project out some dictionary/other data which is packed inside 
the existential? Won't this projection will cause a nice safe _|_ 
instead of a nasty unsafe segfault?


I think it's the extra power of GADTs to tell you more about type 
variables already in play which does the damage.


All the best

Conor

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


Re: [Haskell-cafe] Is Haskell a 5GL?

2006-09-29 Thread Robert Dockins

On Sep 28, 2006, at 8:47 PM, David Curran wrote:


Sorry if this comes across as the rant it is. If you are interested in
doing useful stuff rather then navel gazing please stop here.

Where are compute languages going?
I think multi core, distributed, fault tolerant.
So you would end up with a computer of the sort envisioned by Hillis
in the 80s with his data parallel programs. The only language that
seems even close to this model is Erlang. What am I missing about the
ability of Haskell to distribute across processors or a network?

Say instead of fault tolerant it is fault avoiding.
Can proving programs correct (with Haskell) really reduce our  
workload?

http://www.seas.upenn.edu/~sweirich/wmm/03-benton.pdf


I read that paper as saying formal methods have an extremely steep  
learning curve and large initial investment, but that the learning  
and initial investment pay off over time.  The author found that,  
even in the short time he worked with it, formal methods saved time  
when he needed to modify his definitions (third paragraph in the  
second column).  As with many automation tasks, the payoff comes with  
repeated identical or similar iterations.  Furthermore, his acquired  
knowledge transferred well to an unrelated project.  I can personally  
vouch for many of his experiences, having worked some with Coq myself.



Finally is Haskell a language for programming or a mental gymnasium
that might be the proving ground for concepts in the next popular
language? To quote from a post on the topic Old functional
programming ideas  on programming.reddit.com


I don't know how much you agree with this quote, but for the purposes  
of discussion I'll assume that you have expressed these views  
personally.  You did, after all, preface your message by saying it  
was a rant so I'm going to assume you're prepared for the flames. ;-)



Church-Turing equivalence tells us that all models of recursive
computing have the same formal power. But it tells us nothing about
which models are the most effective way for humans to understand and
express definitions of functions. For some reason I'd expect
researchers in programming languages to have a lot of opinions on this
subject. But they don't seem to talk about it much.


I think the Haskell community is doing better than many in this  
regard.  There is a concurrent thread on haskell-prime occurring  
_right now_ about whether pattern guards should be in Haskell'.  The  
primary point of disagreement is about whether pattern guards are a  
more effective way for humans to understand and express definitions  
of functions or not!  The ages-old disagreement about top-level state  
is similar, if more heated.  Similar for (n+k) patterns, and a host  
of other issues.  The endless discussions about monads often revolve  
around the goal of achieving new and better ways to express  
complicated function definitions.


I think this is because a fundamental value of the Haskell community  
is flexibility of the language.  Many languages are presented to the  
programmer as a complete package, which doesn't encourage them to  
consider the various possible design decisions that went into  
creating that language.  With Haskell, new users are often quickly  
confronted with various different ways of expressing their goals and  
with extensions they can enable (or not) and are forced to consider  
how best to express their program.  I think this is more good than it  
is bad.



Instead, a cynical and mean-spirited person might come to the
conclusion that PL researchers (such as Wadler) are actually just
mathematicians,


You seem to say this like its a bad thing; I completely disagree.  I  
don't think of myself as mean-spirited, and I have no problems  
calling, eg, Wadler a mathematician.  Just as I would call Church and  
Turing and Kleene and Goedel and Milner (etc, etc, etc)  
mathematicians.  If someone were ever to call _me_ a mathematician, I  
would consider it an honor.  Furthermore, if anyone attempted to  
belittle these distinguished persons or their accomplishments by  
calling them just mathematicians, I would begin to question his or  
her qualifications to have an opinion on the subject worthy of  
consideration.


The field mathematics has a long and glorious history of helping  
people to solve real problems.  I don't understand this undercurrent  
of antagonism that some people in our field have towards it.  Let's  
be honest: developing correct programs that perform non-trivial tasks  
and reasoning about them is HARD.  The techniques of mathematics and  
its sister discipline formal logic can help us with these tasks.  I  
find it a little strange that this position even requires a defense.   
All of the other scientific and engineering disciplines embrace the  
mathematics that help them do their work.  I don't believe there are  
very many physicists who would call Newton a mathematician and intend  
it to be a derogatory term.


I 

Re: [Haskell-cafe] Is Haskell a 5GL?

2006-09-29 Thread David Curran

After some thought on your replies I have realised that I was completely wrong.
1. Software needs to be concurrent
Haskell is doing more towards this goal then any other language I know of
2. Software should be provably correct.
Haskell is doing more towards this goal then any other language I know
of. ML and Haskell do seem to be the only communities really trying to
do this. Current systems do need to be easier to use though.
3. Haskell might be too academic
1 and 2 seem to indicate it is academic in the sense of finding out
useful things that a company might consider too blue sky to invest in.
So it might be too academic for now but for five years time maybe not.
   David

On 29/09/06, Robert Dockins [EMAIL PROTECTED] wrote:

On Sep 28, 2006, at 8:47 PM, David Curran wrote:

 Sorry if this comes across as the rant it is. If you are interested in
 doing useful stuff rather then navel gazing please stop here.

 Where are compute languages going?
 I think multi core, distributed, fault tolerant.
 So you would end up with a computer of the sort envisioned by Hillis
 in the 80s with his data parallel programs. The only language that
 seems even close to this model is Erlang. What am I missing about the
 ability of Haskell to distribute across processors or a network?

 Say instead of fault tolerant it is fault avoiding.
 Can proving programs correct (with Haskell) really reduce our
 workload?
 http://www.seas.upenn.edu/~sweirich/wmm/03-benton.pdf

I read that paper as saying formal methods have an extremely steep
learning curve and large initial investment, but that the learning
and initial investment pay off over time.  The author found that,
even in the short time he worked with it, formal methods saved time
when he needed to modify his definitions (third paragraph in the
second column).  As with many automation tasks, the payoff comes with
repeated identical or similar iterations.  Furthermore, his acquired
knowledge transferred well to an unrelated project.  I can personally
vouch for many of his experiences, having worked some with Coq myself.

 Finally is Haskell a language for programming or a mental gymnasium
 that might be the proving ground for concepts in the next popular
 language? To quote from a post on the topic Old functional
 programming ideas  on programming.reddit.com

I don't know how much you agree with this quote, but for the purposes
of discussion I'll assume that you have expressed these views
personally.  You did, after all, preface your message by saying it
was a rant so I'm going to assume you're prepared for the flames. ;-)

 Church-Turing equivalence tells us that all models of recursive
 computing have the same formal power. But it tells us nothing about
 which models are the most effective way for humans to understand and
 express definitions of functions. For some reason I'd expect
 researchers in programming languages to have a lot of opinions on this
 subject. But they don't seem to talk about it much.

I think the Haskell community is doing better than many in this
regard.  There is a concurrent thread on haskell-prime occurring
_right now_ about whether pattern guards should be in Haskell'.  The
primary point of disagreement is about whether pattern guards are a
more effective way for humans to understand and express definitions
of functions or not!  The ages-old disagreement about top-level state
is similar, if more heated.  Similar for (n+k) patterns, and a host
of other issues.  The endless discussions about monads often revolve
around the goal of achieving new and better ways to express
complicated function definitions.

I think this is because a fundamental value of the Haskell community
is flexibility of the language.  Many languages are presented to the
programmer as a complete package, which doesn't encourage them to
consider the various possible design decisions that went into
creating that language.  With Haskell, new users are often quickly
confronted with various different ways of expressing their goals and
with extensions they can enable (or not) and are forced to consider
how best to express their program.  I think this is more good than it
is bad.

 Instead, a cynical and mean-spirited person might come to the
 conclusion that PL researchers (such as Wadler) are actually just
 mathematicians,

You seem to say this like its a bad thing; I completely disagree.  I
don't think of myself as mean-spirited, and I have no problems
calling, eg, Wadler a mathematician.  Just as I would call Church and
Turing and Kleene and Goedel and Milner (etc, etc, etc)
mathematicians.  If someone were ever to call _me_ a mathematician, I
would consider it an honor.  Furthermore, if anyone attempted to
belittle these distinguished persons or their accomplishments by
calling them just mathematicians, I would begin to question his or
her qualifications to have an opinion on the subject worthy of
consideration.

The field mathematics has a long and glorious history of helping
people 

[Haskell-cafe] Greetings...

2006-09-29 Thread Seth Gordon
I've finally gotten enough round tuits to learn Haskell, and now that
I've done some of the exercises from _The Haskell School of Expression_
and I finally (think I) understand what a monad is, the language is
making a lot more sense to me (although my code is not always making so
much sense to the compiler :-).

My employer (MetaCarta) makes a search engine that can recognize
geographic data.  My group within MetaCarta is responsible for building
the Geographic Data Module within our software.  To do this, we slurp
a heap of geographic and linguistic data from a variety of sources,
normalize it, and then use some algorithms (that I'm not allowed to
describe) to generate the module.

This seems like the sort of task that cries out for a
functional-programming approach, and that's what we use, sorta: a lot of
the code that I'm responsible for is SQL, with chains of CREATE TEMP
TABLE X AS [insert very complicated query here], some C++ for the parts
that would be very time-consuming or impossible to implement in SQL, and
shell scripts to tie everything together.

I told my tech lead that I want to try porting some of this code to
Haskell in the hope that it would run faster and/or be easier to read.
He said I should spend two work days on the project and then be prepared
to convince my co-workers that further research in this vein is (or is
not) worth doing.

So before I embark on day 1 of the project, I thought I should check and
see if anyone on this list has used Haskell to munge a ten-million-row
database table, and if there are any particular gotchas I should watch
out for.

adTHANKSvance

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


[Haskell-cafe] How can I redirect stdout?

2006-09-29 Thread Matthew Bromberg
I'm reposting this in it's own new thread since I think it involves a 
general issue beyond exporting Haskell DLLs.


I am having some problems with GHCs stdout when a Haskell program is 
called from a windows program.




As I noted earlier I am calling some Haskell code from C as a bridge to 
being able to

ultimately call Haskell from Matlab 6.5.

The Haskell code is compiled into a .DLL file on a windows machine.
Matlab calls some C code which then calls the Haskell code.

As soon as it gets into the Haskell code I get this run time error in 
ghcDLL.dll


stdout: hPutChars: invalid argument (Bad File Descriptor)

The Haskell code seems to work correctly if called from a stand-alone C 
program. Moreover, if I scrub all print statements from the Haskell 
code, it appears to run correctly from Matlab.


Matlab does not properly redirect stdout so any printf calls from the C 
code simply fail to print.

However Haskell's behavior is to halt after generating a runtime error.

The C code used to generate the Haskell .dll is of course mingw gcc, but 
the C code used to create my Matlab mex file is Microsoft VC++ 6.0.  I 
tried to redirect stdout using freopen() in C, but that never seems to 
work with Microsoft.  At any rate it certainly doesn't effect Haskells 
use of stdout.  I think in general for windows programs there is no 
stdout defined, whereas it's always defined for console programs.


My question is, is there some way I can redirect stdout from inside 
Haskell so that all output is sent to a file?  Is there an equivalent of 
freopen() in Haskell that works?

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


Re: Re: [Haskell-cafe] Is Haskell a 5GL?

2006-09-29 Thread Nicolas Frisby

snip



Call me elitist if you want, but I don't want anyone who refuses or
is unable to learn calculus to be, eg, a civil engineer.  He don't
have to be an expert in real analysis, but if he don't understand the
basics, I don't want him building any bridges that I'm going to be
driving on!



Excellent point that certainly does not make one an elitist. Many
engineering disciplines such as civil, chemical, architectural,
aerospace, etc. enjoy a mature relationship between their best design
practices and mathematics/hard science. Also note that a bad bridge
almost certainly endangers multiple peoples' lives (consider the
history behind http://www.ironring.ca/).


In a similar way, if a someone refuses or is unable to learn the
mathematical foundations of computation, I don't think I really want
him programming any systems that I'm going to be relying on.  He
don't need to be an expert in category theory, but if programmers
aren't learning the skills they need to understand the basics and
mathematical notation of PL theory, then something is very, very
wrong.  (Not to beat you over the head with my point, but what I'm
saying is that programmers really ought to know this stuff and the
fact that most do not is a terrible state of affairs).



I hope to someday agree with this, but for now I cannot. The fact of
the matter is it's a rare case when a programmer's lack of
mathematical background threatens lives. If my GUI crashes, I'm angry
but not injured. Programmers make a living without the math background
because the vast majority of employers don't seek it--their products
simply don't need it.

Note that I said rare case; I think there are plenty of safety
critical programs out there. Consider the shuttle, deep-sea equipment,
military or medical equipment, etc. Now if the programmer you're
worred about is on one of these projects, I most certainly share your
unease.

Software engineering is as of yet misnamed. A professional engineer's
design work should never include figuring out why the first attempt
exploded/collapsed/failed--professionals in mature engineering fields
only debug catastrophes.

My intended takeaway is that design in software engineering does not
yet compare to design in the mature engineering fields. In my
engineering-centric opinion, the goal of computer science is to enrich
the design principles of software engineering so that it does compare.

[Disclaimer regarding that paragraph's punch-line: there's obvious
gradations between engineering fields, as well as gradations within a
field between researchers progressing the best practices and
professionals simply using best practices.]


 If a responsible scientist wanted to counter this cynical,
 mean-spirited, and generally Luddite and Philistine argument, what
 would he or she say?

Mu




Rob Dockins

Speak softly and drive a Sherman tank.
Laugh hard; it's a long way to the bank.
   -- TMBG



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



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


Re: Re: [Haskell-cafe] Is Haskell a 5GL?

2006-09-29 Thread Gene A

Nicolas Frisby said:
{}
The fact of the matter is it's a rare case when a programmer's lack of
mathematical background threatens lives. If my GUI crashes, I'm angry
but not injured. Programmers make a living without the math background
because the vast majority of employers don't seek it--their products
simply don't need it.

Note that I said rare case; I think there are plenty of safety
critical programs out there. Consider the shuttle, deep-sea equipment,
military or medical equipment, etc. Now if the programmer you're
worried about is on one of these projects, I most certainly share your
unease.
{...}

All those angry office workers with those crashing GUI's cost hundreds
of millions of dollars every year... arguably some billions perhaps..
And besides deep space probes and aircraft, there are many machines
out in industrial plants that have some pretty dangerous processes and
such running on computer instructions... right to a dryer that maybe
doesn't shut off the heating element when it should due to a glitch in
a program... and burns up.
 Now as to the need for EVERY programmer to know discreet mathematics
and know how to run a proof through a theorem prover, and understand
fully all the nuances of lambda calculus, and pi calculus, and all
those other calculuses and such.. well, I guess that is why I am happy
to be using tools like Haskell, or the ML family of languages, because
at least the tool is built by folks the like of  Wadler, Peyton
Jones, and many other out and out academics and highly skilled and
brilliant mathematicians.  That means that I benefit from the type
checking {and inference} that make my programs more likely to be
correct on the first go.  I have found that to be the case so far.
  I was able to build an equation solver in three variable and
basically unlimited number of terms in about 6 hours, that would have
taken probably weeks to complete in any language other than Haskell or
one of the other functionals that support higher order functions, and
the mapping and folding functions, and list comprehensions etc.
   I am just a happy camper that I have the ability to use such fine
tools, and not have to be lost in the catacombs of mediocrity: ie.
Java, C++, C, and C#.

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


[Haskell-cafe] smallest double eps

2006-09-29 Thread Tamas K Papp
Hi,

Is there a built-in constant in Haskell (or, if it is
compiler-specific, in ghc) that gives the smallest positive floating
point number x such that 1+x /= x?  Some languages refer to that as
double.eps or similar.  I need it for numeric algorithms.

Thanks,

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


Re: [Haskell-cafe] smallest double eps

2006-09-29 Thread Joachim Breitner
Hi,

Am Freitag, den 29.09.2006, 19:30 -0400 schrieb Tamas K Papp:
 the smallest positive floating point number x such that 1+x /= x?
That would be the smallest positive number, woudn't it?

Do you mean the smalles postive number x with 1+x /= 1?

Greetings,
Joachim


-- 
Joachim Breitner
  e-Mail: [EMAIL PROTECTED]
  Homepage: http://www.joachim-breitner.de
  ICQ#: 74513189
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] smallest double eps

2006-09-29 Thread Tamas K Papp
On Sat, Sep 30, 2006 at 12:20:16AM +, Joachim Breitner wrote:
 Hi,
 
 Am Freitag, den 29.09.2006, 19:30 -0400 schrieb Tamas K Papp:
  the smallest positive floating point number x such that 1+x /= x?
 That would be the smallest positive number, woudn't it?
 
 Do you mean the smalles postive number x with 1+x /= 1?

Hi Joachim,

Specifically, I would be happy with the smallest Double that makes the
statement true.  I need it as a convergence bound for an iterative
algorithm.  Anyhow, thanks for the clarification, but I would be
happier with an answer.

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


Re: [Haskell-cafe] smallest double eps

2006-09-29 Thread Lennart Augustsson
Haskell doesn't provide such a value, but you could easily compute it  
from from the values given in the RealFloat class.  It tells you the  
base, number of digits in mantissa, etc.


As for using such an eps in a convergence test I'd be very careful.   
How do you know that your iteration doesn't make the value bounce  
back and forth with more than eps?


-- Lennart

On Sep 29, 2006, at 20:26 , Tamas K Papp wrote:


On Sat, Sep 30, 2006 at 12:20:16AM +, Joachim Breitner wrote:

Hi,

Am Freitag, den 29.09.2006, 19:30 -0400 schrieb Tamas K Papp:

the smallest positive floating point number x such that 1+x /= x?

That would be the smallest positive number, woudn't it?

Do you mean the smalles postive number x with 1+x /= 1?


Hi Joachim,

Specifically, I would be happy with the smallest Double that makes the
statement true.  I need it as a convergence bound for an iterative
algorithm.  Anyhow, thanks for the clarification, but I would be
happier with an answer.

Tamas
___
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] smallest double eps

2006-09-29 Thread Tamas K Papp
On Fri, Sep 29, 2006 at 09:26:27PM -0400, Lennart Augustsson wrote:

 As for using such an eps in a convergence test I'd be very careful.   
 How do you know that your iteration doesn't make the value bounce  
 back and forth with more than eps?

Hi Lennart,

Thanks for the answer, I will try it.

I am not using eps, but rather a value derived from eps by analyzing
the algorithm (eg eps^0.25).  Your answer will help me calculate that
directly.

Thanks,

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


Re: [Haskell-cafe] Is Haskell a 5GL?

2006-09-29 Thread Tamas K Papp
On Mon, Sep 25, 2006 at 03:27:32PM +0200, Henning Thielemann wrote:

Hi Henning,

 Actually, laziness allows me to formulate algorithms that look more like
 the specification of the problem than the solution. E.g., I can formulate
 the solution of a differential equation in terms of a power series or time
 series in that way. However I have to put some effort into formulating it
 in a way that works. E.g. I'm only able to solve such equations if it is
 possible to express the second derivative in terms of the first and the
 zeroth one. Computer algebra systems are essentially better here.

In my experience, most people use CAS interactively: they encounter an
integral or a PDE that's difficult to solve, so they type it into
Mathematica (which frequently cannot solve it either, then you go
crazy, numerical, or both ;-).  It is more like a sophisticated
symbolic calculator with a lot of patterns built in for manipulating
expressions.

Mathematica has features of a programming language, but most people I
know are not using those when manipulating formulas, and conversely,
when _programming_ in Mathematica (ie writing code and then executing
it do so something repetitive) they rarely do anything symbolic.

CAS are great for specific purposes, especially for replacing those
tomes which have solutions of equations/ODEs/PDEs/integrals etc in
them, and some CAS have Algol-style flow control and numerical methods
which you can use for solving numerical problems, but the two are
almost never mixed.

Best,

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


Re: [Haskell-cafe] smallest double eps

2006-09-29 Thread Chad Scherrer

Tamas,

You might want to read Joachim's post more carefully - he's trying to
help you, and I think he makes a good point.

-Chad


 Am Freitag, den 29.09.2006, 19:30 -0400 schrieb Tamas K Papp:
  the smallest positive floating point number x such that 1+x /= x?
 That would be the smallest positive number, woudn't it?

 Do you mean the smalles postive number x with 1+x /= 1?

Hi Joachim,

Specifically, I would be happy with the smallest Double that makes the
statement true.  I need it as a convergence bound for an iterative
algorithm.  Anyhow, thanks for the clarification, but I would be
happier with an answer.

Tamas


--

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


End of Haskell-Cafe Digest, Vol 37, Issue 92





--

Chad Scherrer

Time flies like an arrow; fruit flies like a banana -- Groucho Marx
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] smallest double eps

2006-09-29 Thread Tamas K Papp
On Fri, Sep 29, 2006 at 06:53:35PM -0700, Chad Scherrer wrote:

 Tamas,
 
 You might want to read Joachim's post more carefully - he's trying to
 help you, and I think he makes a good point.

Chad,

If his point is that there is no smallest positive number, then I
think I understand it, thanks.  I should have said that I was looking
for the smallest positive number Double can represent, but thought
that was clear from the context.

If this is not his point, I'd really appreciate an explanation.

Thanks,

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