Re: [Haskell-cafe] for loops and 2d arrays in haskell

2007-01-19 Thread Ketil Malde

Fernan Bolando wrote:

what is the simplest way to implement the following code in haskell?
it's just printing the contents of 2D array.

for(i = 0; i  imax; i++){
for(n = 0; n  nmax; n++){
printf(%i:%i = %f\n, array[i][n]);
}
}

*%* ghci
  ___ ___ _
* / _ \ /\  /\/ __(_)
/ /_\// /_/ / /  | |  GHC Interactive, version 6.6, for Haskell 98.
/ /_\\/ __  / /___| |  http://www.haskell.org/ghc/
\/\/ /_/\/|_|  Type :? for help.

Loading package base ... linking ... done.
Prelude* :m + Data.Array
*Prelude Data.Array* let a = listArray ((0,0),(2,2)) [1..9]

  This is how it looks by default:

*Prelude Data.Array* a
array ((0,0),(2,2)) 
[((0,0),1),((0,1),2),((0,2),3),((1,0),4),((1,1),5),((1,2),6),((2,0),7),((2,1),8),((2,2),9)]


  'assocs' builds the corresponding assoc list:

*Prelude Data.Array *assocs a
[((0,0),1),((0,1),2),((0,2),3),((1,0),4),((1,1),5),((1,2),6),((2,0),7),((2,1),8),((2,2),9)]

  'map show' converts it into a list of strings:

*Prelude Data.Array* map show $ assocs a
[((0,0),1),((0,1),2),((0,2),3),((1,0),4),((1,1),5),((1,2),6),((2,0),7),((2,1),8),((2,2),9)]

   'unlines' to convert to a single string where each list element is 
one line, and 'putStrLn' to print it:


*Prelude Data.Array *putStrLn $ unlines $ map show $ assocs a
**((0,0),1)
((0,1),2)
((0,2),3)
((1,0),4)
((1,1),5)
((1,2),6)
((2,0),7)
((2,1),8)
((2,2),9)
*
  *To get the exact same output, replace 'show' with a custom-built 
function.

*
Prelude Data.Array* putStrLn $ unlines $ map (\((i,j),v)- show 
i++:++show j++=++show v) $ assocs a

0:0=1
0:1=2
0:2=3
1:0=4
1:1=5
1:2=6
2:0=7
2:1=8
2:2=9

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


Re: [Haskell-cafe] IO in lists

2007-01-19 Thread Magnus Therning
Thanks for all the excellent answers to my original question.  Somehow
it feels like I advanced and got one level closer to a black belt in
Haskell due to this; I've now legitimately used a function from
System.IO.Unsafe :-)

I tried to document it all: http://therning.org/magnus/archives/249

/M

http://liw.iki.fi/liw/log/2007-01.html#20070116b

-- 
Magnus Therning (OpenPGP: 0xAB4DFBA4)
[EMAIL PROTECTED] Jabber: [EMAIL PROTECTED]
http://therning.org/magnus


pgpZG9AiJbjF8.pgp
Description: PGP signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Fractional sqrt

2007-01-19 Thread Henning Thielemann

On Thu, 18 Jan 2007, Novák Zoltán wrote:

 I have to admit that I do not fully understand the Haskell numerical tower... 
 Now I'm using the Newton method:
 
 mysqrt :: (Fractional a) = a - a
 mysqrt x = (iterate (\y - (x / y + y) / 2.0 ) 1.0) !!2000
 
 But I want a faster solution. (Not by replacing 2000 with 100... :)

Newton method for sqrt is very fast. It converges quadratically, that is
in each iteration the number of correct digits doubles. The problem is to
find a good starting approximation. What about comparing powers of two and
their squares against 'x' and use an appropriate power of two as starting
value? Sure, this will require Real instance and won't work on complex
numbers.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: IO in lists

2007-01-19 Thread Ferenc Wagner
Magnus Therning [EMAIL PROTECTED] writes:

 Thanks for all the excellent answers to my original question.  Somehow
 it feels like I advanced and got one level closer to a black belt in
 Haskell due to this; I've now legitimately used a function from
 System.IO.Unsafe :-)

 I tried to document it all: http://therning.org/magnus/archives/249

I wonder whether the unsafeInterleaved solution is guarranteed to work
as per your specification.  Couldn't it read a character, write it,
then read three characters, write two, read one more then write two
again, and so on?  It has to catch up at the end, but needn't stay
synchronized during the process, perhaps...
-- 
Thanks,
Feri.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Article review: Category Theory

2007-01-19 Thread Ulf Norell


On Jan 18, 2007, at 10:09 PM, Yitzchak Gale wrote:


I wrote:

Will (id :: A - A $!) do the trick?


Ulf Norell wrote:

The problem is not with id, it's with composition. For any f and g we
have

f . g = \x - f (g x)

So _|_ . g = \x - _|_ for any g.


OK, so then how about

f .! g = ((.) $! f) $! g


That should probably do the trick.

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


Re: [Haskell-cafe] Re: IO in lists

2007-01-19 Thread Magnus Therning
On Fri, Jan 19, 2007 at 11:19:16 +0100, Ferenc Wagner wrote:
Magnus Therning [EMAIL PROTECTED] writes:

 Thanks for all the excellent answers to my original question.  Somehow
 it feels like I advanced and got one level closer to a black belt in
 Haskell due to this; I've now legitimately used a function from
 System.IO.Unsafe :-)

 I tried to document it all: http://therning.org/magnus/archives/249

I wonder whether the unsafeInterleaved solution is guarranteed to work
as per your specification.  Couldn't it read a character, write it,
then read three characters, write two, read one more then write two
again, and so on?  It has to catch up at the end, but needn't stay
synchronized during the process, perhaps...

Good point!

However, for my uses right now it doesn't matter. So rather than find a
problem with the code you've found a problem with my requirements.  Of
course that's a good thing as well since you've helped me understand the
problem better :-)

/M

-- 
Magnus Therning (OpenPGP: 0xAB4DFBA4)
[EMAIL PROTECTED] Jabber: [EMAIL PROTECTED]
http://therning.org/magnus


pgphuAhyjLvaL.pgp
Description: PGP signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: IO in lists

2007-01-19 Thread Joachim Breitner
Hi,

Am Freitag, den 19.01.2007, 11:19 +0100 schrieb Ferenc Wagner:
 Magnus Therning [EMAIL PROTECTED] writes:
 
  Thanks for all the excellent answers to my original question.  Somehow
  it feels like I advanced and got one level closer to a black belt in
  Haskell due to this; I've now legitimately used a function from
  System.IO.Unsafe :-)
 
  I tried to document it all: http://therning.org/magnus/archives/249
 
 I wonder whether the unsafeInterleaved solution is guarranteed to work
 as per your specification.  Couldn't it read a character, write it,
 then read three characters, write two, read one more then write two
 again, and so on?  It has to catch up at the end, but needn't stay
 synchronized during the process, perhaps...

I think it is: 
“unsafeInterleaveIO allows IO computation to be deferred lazily. When
passed a value of type IO a, the IO will only be performed when the
value of the a is demanded. This is used to implement lazy file reading,
see hGetContents.”[1]

If it would read a value that is not needed, it would violate the
documented behaviour (the “only .. when .. demanded” is important).

Greetings,
Joachim

[1] 
http://haskell.org/ghc/docs/latest/html/libraries/base/System-IO-Unsafe.html#v%3AunsafeInterleaveIO
-- 
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] Fractional sqrt

2007-01-19 Thread Novák Zoltán
Hi,

Thanks for the answers. The best solution would be a general purpose
 arbitrary precision math library for Haskell. I found two:

http://medialab.freaknet.org/bignum/
http://r6.ca/FewDigits/

I think both uses power series and have trigonometric functions too. (I only
need sqrt, so probably I will not use them, just the simple Newton alg.)

It would be great, if a fast implementation of arbitrary precision real
arithmetic Class would be part of the Standard libraries. Because  Haskell is
so great for numerical computations already (functions, composing functions,
higher order f. with typechecking), a good math library would make Matlab
obsolete. :)
Zoltan Novak

ps. Call me Zoltan (that is my first name), just we write it in different 
order in Hungary. (Names are in hungarian notation here: the type description 
precedes the actual name)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] for loops and 2d arrays in haskell

2007-01-19 Thread Yitzchak Gale

Hi Fernan,

You wrote:

 what is the simplest way to implement the following code in haskell?
 it's just printing the contents of 2D array.

 for(i = 0; i  imax; i++){
 for(n = 0; n  nmax; n++){
 printf(%i:%i = %f\n, array[i][n]);
 }
 }


There are many different ways of representing the
concept of a 2D array in Haskell.

Sebastian Sylvan wrote:

sequence [ putStrLn (show i ++ : ++ show n ++  =  show (arr!(i,n)) )
   | (i,n) - indices arr ]


Ketil Malde wrote:

putStrLn $ unlines $ map (\((i,j),v)- show
i++:++show j++=++show v) $ assocs a


Sebastian and Ketil are both thinking of the type:

import Data.Array
arr :: Array (Int, Int) Int

Ketil also showed how to build the array to begin with.

That type is quite similar to arrays in C, except that
they are immutable. There are also mutable arrays,
which are almost exactly like arrays in C, but they
are a bit more clumsy to work with.

There are other ways of representing 2D arrays
that are less similar to arrays in C, and perhaps
more natural in Haskell.

For simplicity, let me define a function that prints
one element, corresponding to your printf:

showElt :: Show a = Int - Int - a - String
showElt i j x = show i ++ : ++ show j ++ = ++ show x

This is exactly what Sebastian and Ketil used.
Note that I am not requiring that the array contains
integers anymore - any type that Haskell knows how
to print (any instance of the Show class) will do.

One way to represent your array is the type:

arr :: Show a = [[a]]

You could build it like this:

arr = [[1,2,3],[4,5,6],[7,8,9]]

You could print it like this:

putStrLn $ unlines [showElt i n x | (row,i) - zip arr [0..], (x,n) -
zip row [0..]]

Another way is as an association list (this is what Ketil got
out of the Array type using the assocs function):

arr :: Show a = [((Int, Int), a]

arr = zip [(i,n) | i - [0..2], n -  [0..2]] [1,2,3,4,5,6,7,8,9]

putStrLn $ unlines [showElt i n x | ((i,n),x) - arr]

If you also need random access to the array, you should
look at Data.Sequence and Data.IntMap from the standard
library (in addition to mutable arrays, as mentioned above).

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


Re: [Haskell-cafe] Simple HTTP lib for Windows?

2007-01-19 Thread Björn Bringert

Greg Fitzgerald wrote:
I'd like to write a very simple Haskell script that when given a URL, 
looks up the page, and returns a string of HTML. I don't see an HTTP 
library in the standard libs, and the one in Hackage requires Windows 
machines have GHC and MinGW to be installed and in the PATH. 

Is there a simple way to get the contents of a webpage using Haskell on 
a Windows box?


I agree with other posters that the Network.HTTP API should be made more 
easy to use. I will happily accept patches for this.


The HTTP package homepage (http://www.haskell.org/http/) mentioned the 
GHC and MinGW requirements you cite, but those seemed to be out of date. 
You should be able to use plain Cabal to install the HTTP package for 
any recent GHC or Hugs.


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


Re: [Haskell-cafe] Fractional sqrt

2007-01-19 Thread Yitzchak Gale

Hi Zoltán,


I only need sqrt, so probably I will... use... just
the simple Newton alg.


It is still not clear to me what type you want
to work in. Is it Rational? In that case, you don't
need the Newton algorithm.

realToFrac . sqrt . realToFrac

works fine, as you originally suggested. If that gives
too much precision, you can use

(`approxRational` epsilon) . sqrt . realToFrac

Newton will not work in general for Fractional. It works
for Floating, but there you already have the sqrt function.
Are you using a type that has a Fractional instance,
does not have a Floating instance, and Newton works
and is needed? What type is that?


a good math library would make Matlab obsolete. :)


Yes, that would certainly be nice. This has been
discussed at length several times on this list in the past.
I wonder if there has been any further progress on it.

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


Re: [Haskell-cafe] Article review: Category Theory

2007-01-19 Thread Ulf Norell


On Jan 19, 2007, at 1:06 PM, Yitzchak Gale wrote:


Hmm. I wrote:


for simplicity, we will ignore these distinctions


But do we really want to do that? Are the monads
that we use every day in Haskell really monads
if we check the axioms using (.!) instead of (.)
as we should? I'm not so sure anymore...


Personally I think that the distinction between _|_ and \x - _|_ is  
a mistake and should be ignored whenever possible.


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


Re: [Haskell-cafe] Article review: Category Theory

2007-01-19 Thread Nils Anders Danielsson
On Fri, 19 Jan 2007, Ulf Norell [EMAIL PROTECTED] wrote:

 Personally I think that the distinction between _|_ and \x - _|_ is
 a mistake and should be ignored whenever possible.

If you want to write an accessible tutorial you should probably use a
total programming language, or at least the total fragment of some
language, for the programming-related examples. I'd mention the
problems with Haskell, restrict the language in some way, and then
move on.

-- 
/NAD

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


[Haskell-cafe] Re: Article review: Category Theory

2007-01-19 Thread apfelmus
Ulf Norell wrote:
 In the section on the category laws you say that the identity morphism
 should satisfy
 
   f . idA = idB . f
 
 This is not strong enough. You need
 
   f . idA = f = idB . f
 
 Unfortunately, fixing this means that the category Hask is no longer a
 category since
 
   _|_ . id = \x - _|_ =/= _|_

Neil Mitchell wrote:
 Isn't _|_ = \x - _|_?
 
 _|_ `seq` () = _|_
 (\x - _|_) `seq` () = ()
 
 Whether this is the fault of seq or not is your call...

Subtle, subtle.

From the point of view of denotational semantics, the functions (x
\mapsto _|_) and _|_ are the same as equality and the semantic
approximation order are defined point-wise. Usually, the morphisms of
some category arising from a (non-normalizing or polymorphic) lambda
calculus are given by such partial functions.

The key point about lambda calculi is that the external morphisms sets
can be internalized, i.e. represented as objects of the category
themselves. So, the set of morphisms from 'Integer' to 'Integer' can be
represented by the type 'Integer - Integer'. But, as the example with
`seq` shows, this is not entirely true. Apparently, Haskell represents
function types in a boxed way, i.e. they are lifted by an extra _|_:

   newtype ClosureInt2Int = Closure (Integer - Integer)#

Thus, Hask is not a category, at least not as defined in the article.
The problem is that (either) morphisms or the morphism composition ('.')
are not internalized correctly in Haskell.

Regards,
apfelmus

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


Re: [Haskell-cafe] Fractional sqrt

2007-01-19 Thread Lennart Augustsson
If it's arbitrary precision floating point that you want then sqrt  
should where it already is, as a member of Floating.  (I find  
arbitrary precision real to be an oxymoron, the real numbers are  
the real numbers, they already have arbitrary precision.)
For a real number module, you can use, e.g., David Lester's  
implementation, http://www.augustsson.net/Darcs/CReal/


-- Lennart

On Jan 19, 2007, at 07:13 , Novák Zoltán wrote:


Hi,

Thanks for the answers. The best solution would be a general purpose
 arbitrary precision math library for Haskell. I found two:

http://medialab.freaknet.org/bignum/
http://r6.ca/FewDigits/

I think both uses power series and have trigonometric functions  
too. (I only
need sqrt, so probably I will not use them, just the simple Newton  
alg.)


It would be great, if a fast implementation of arbitrary precision  
real
arithmetic Class would be part of the Standard libraries. Because   
Haskell is
so great for numerical computations already (functions, composing  
functions,
higher order f. with typechecking), a good math library would make  
Matlab

obsolete. :)
Zoltan Novak

ps. Call me Zoltan (that is my first name), just we write it in  
different
order in Hungary. (Names are in hungarian notation here: the type  
description

precedes the actual name)
___
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: Article review: Category Theory

2007-01-19 Thread Lennart Augustsson
And this is why some of us think that adding polymorphic seq to  
Haskell was a mistake. :(


-- Lennart


On Jan 19, 2007, at 08:05 , [EMAIL PROTECTED] wrote:


Ulf Norell wrote:
In the section on the category laws you say that the identity  
morphism

should satisfy

  f . idA = idB . f

This is not strong enough. You need

  f . idA = f = idB . f

Unfortunately, fixing this means that the category Hask is no  
longer a

category since

  _|_ . id = \x - _|_ =/= _|_


Neil Mitchell wrote:

Isn't _|_ = \x - _|_?


_|_ `seq` () = _|_
(\x - _|_) `seq` () = ()

Whether this is the fault of seq or not is your call...


Subtle, subtle.


From the point of view of denotational semantics, the functions (x

\mapsto _|_) and _|_ are the same as equality and the semantic
approximation order are defined point-wise. Usually, the morphisms of
some category arising from a (non-normalizing or polymorphic) lambda
calculus are given by such partial functions.

The key point about lambda calculi is that the external morphisms  
sets

can be internalized, i.e. represented as objects of the category
themselves. So, the set of morphisms from 'Integer' to 'Integer'  
can be

represented by the type 'Integer - Integer'. But, as the example with
`seq` shows, this is not entirely true. Apparently, Haskell represents
function types in a boxed way, i.e. they are lifted by an extra _|_:

   newtype ClosureInt2Int = Closure (Integer - Integer)#

Thus, Hask is not a category, at least not as defined in the article.
The problem is that (either) morphisms or the morphism composition  
('.')

are not internalized correctly in Haskell.

Regards,
apfelmus

___
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] Fractional sqrt

2007-01-19 Thread ajb
G'day all.

Quoting Henning Thielemann [EMAIL PROTECTED]:

 Newton method for sqrt is very fast. It converges quadratically, that is
 in each iteration the number of correct digits doubles. The problem is to
 find a good starting approximation.

Yup.  So how might we go about doing this?

First off, note that for fractions, sqrt(p/q) = sqrt p / sqrt q.

Secondly, note that for floating point numbers,
sqrt(m * b^e) = sqrt m * b^(e/2).

So an approach to get an initial approximation to p/q might be:

1. Compute approximate square roots for p and q, then divide.

2. For each of p and q, express as a floating-point number
m * b^(2e), compute an approximate square root for m (which will
be less than 2b), then multiply by b^e.

We've now reduced the range of approximate square roots
that we want to numbers in the range 0 to 2b, where b is a parameter
that you can use to tune the algorithm.

OK, so let's pick b=16 out of the air.  Our code might look something
like this:

sqrtApprox :: Rational - Rational
sqrtApprox x = sqrtApprox' (numerator x) / sqrtApprox' (denominator x)

sqrtApprox' :: Integer - Rational
sqrtApprox' n
| n  0 = error sqrtApprox'
| otherwise = approx n 1
where
approx n acc
| n  256   = (acc%1) * approxSmallSqrt (fromIntegral n)
| otherwise = approx (n `div` 256) (acc*16)

approxSmallSqrt :: Int - Rational
approxSmallSqrt n = {- detail omitted -}

The approxSmallSqrt function is a good candidate for the memoising
CAFs approach:

http://haskell.org/hawiki/MemoisingCafs

You can populate the memo table by using a fixed number of iterations
of the Newton-Raphson algorithm on a suitably sane initial estimate.

You can get a slightly better estimate by being a bit more careful about
rounding.  Suppose that n = 2 + 256 * n', then a good estimate for
sqrt n is 16 * sqrt n'.  But if n = 255 + 256 * n', the algorithm above
would also estimate sqrt n as 16 * sqrt n'.  It's only slightly more
expensive (and occasionally better) to round up instead, and use
16 * sqrt (n'+1) as the estimate.

So you might want to do this instead:

sqrtApprox' :: Integer - Rational
sqrtApprox' n
| n  0 = error sqrtApprox'
| otherwise = approx n 1
where
approx n acc
| n  272
= (acc%1) * approxSmallSqrt (fromIntegral n)
| r  16
= approx q (acc*16)
| otherwise
= approx (q+1) (acc*16)
where (q,r) = n `divMod` 256

approxSmallSqrt :: Int - Rational
approxSmallSqrt n = {- detail omitted -}

I've also extended the range for approxSmallSqrt here from (0,255) to
(0,271).  It is left as an exercise as to why this might be a good idea.

(Hint: 272 is approximately 16.5*16.5.)

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


Re: [Haskell-cafe] Fractional sqrt

2007-01-19 Thread Thorkil Naur
Hello,

On Friday 19 January 2007 16:48, [EMAIL PROTECTED] wrote:
 ...
 sqrtApprox' :: Integer - Rational 
 sqrtApprox' n
 | n  0 = error sqrtApprox'
 | otherwise = approx n 1
 where
 approx n acc
 | n  256   = (acc%1) * approxSmallSqrt (fromIntegral n)
 | otherwise = approx (n `div` 256) (acc*16)
 ...

In the Haskell report section 14.4 (and also e.g. in GHC.Float), we find

-- Compute the (floor of the) log of i in base b.
-- Simplest way would be just divide i by b until it's smaller then b, but 
that would
-- be very slow!  We are just slightly more clever.
integerLogBase :: Integer - Integer - Int
integerLogBase b i
   | i  b = 0
   | otherwise = doDiv (i `div` (b^l)) l
   where
-- Try squaring the base first to cut down the number of divisions.
 l = 2 * integerLogBase (b*b) i

 doDiv :: Integer - Int - Int
 doDiv x y
| x  b = y
| otherwise = doDiv (x `div` b) (y+1)

Something like this could probably be used to find a suitable sqrt 
approximation for an Integer:

  sqrtApproxViaLog i = 2^(integerLogBase 2 i `div`2)

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


Re: [Haskell-cafe] Article review: Category Theory

2007-01-19 Thread David House

On 19/01/07, Yitzchak Gale [EMAIL PROTECTED] wrote:

OK, thanks! Time to re-write the Note
paragraph yet again. Here goes a first
shot at it:


This was a bit much to include in the introduction section, so I added
a footnote. Hopefully I got everything right; I tend to take the view
that we should ignore seq when talking about abstract language
properties so if the comment seems biased towards blaming seq, that's
why. :)

--
-David House, [EMAIL PROTECTED]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Article review: Category Theory

2007-01-19 Thread Brian Hulley

Lennart Augustsson wrote:


On Jan 19, 2007, at 08:05 , [EMAIL PROTECTED] wrote:

Thus, Hask is not a category, at least not as defined in the article.
The problem is that (either) morphisms or the morphism composition
('.')
are not internalized correctly in Haskell.




And this is why some of us think that adding polymorphic seq to
Haskell was a mistake. :(


I've often wondered why seq is the primitive and not $!
Would this solve the problem?
Is there any solution that would allow excess laziness to be removed from a 
Haskell program such that Hask would be a category?


Thanks, Brian.
--
http://www.metamilk.com 


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


Re: [Haskell-cafe] Re: Article review: Category Theory

2007-01-19 Thread Neil Mitchell

Hi Brian,


I've often wondered why seq is the primitive and not $!
Would this solve the problem?
Is there any solution that would allow excess laziness to be removed from a
Haskell program such that Hask would be a category?


class Seq a where
   seq :: a - b - b

Then you have a different seq based on the types, and it doesn't go
wrong. You would probably want deriving Seq support.

Thanks

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


Re: [Haskell-cafe] Simple HTTP lib for Windows?

2007-01-19 Thread Greg Fitzgerald

Alistair, Neil, Brad, Yitzchak, Bjorn,

Thanks all for your help.

-Greg


On 1/19/07, Björn Bringert [EMAIL PROTECTED] wrote:


Greg Fitzgerald wrote:
 I'd like to write a very simple Haskell script that when given a URL,
 looks up the page, and returns a string of HTML. I don't see an HTTP
 library in the standard libs, and the one in Hackage requires Windows
 machines have GHC and MinGW to be installed and in the PATH.

 Is there a simple way to get the contents of a webpage using Haskell on
 a Windows box?

I agree with other posters that the Network.HTTP API should be made more
easy to use. I will happily accept patches for this.

The HTTP package homepage (http://www.haskell.org/http/) mentioned the
GHC and MinGW requirements you cite, but those seemed to be out of date.
You should be able to use plain Cabal to install the HTTP package for
any recent GHC or Hugs.

/Björn

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


Re: [Haskell-cafe] Re: Article review: Category Theory

2007-01-19 Thread Jan-Willem Maessen


On Jan 19, 2007, at 1:07 PM, Brian Hulley wrote:


Lennart Augustsson wrote:


On Jan 19, 2007, at 08:05 , [EMAIL PROTECTED] wrote:
Thus, Hask is not a category, at least not as defined in the  
article.

The problem is that (either) morphisms or the morphism composition
('.')
are not internalized correctly in Haskell.




And this is why some of us think that adding polymorphic seq to
Haskell was a mistake. :(


I've often wondered why seq is the primitive and not $!
Would this solve the problem?


Sadly, no:

seq = (const id $!)

-Jan-Willem Maessen

Is there any solution that would allow excess laziness to be  
removed from a Haskell program such that Hask would be a category?


Thanks, Brian.
--
http://www.metamilk.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe




smime.p7s
Description: S/MIME cryptographic signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Final Call for Papers: TFP 2007, New York, USA

2007-01-19 Thread TFP 2007
CALL FOR PAPERS
Trends in Functional Programming 2007
New York, USA
April 2-4, 2007
http://cs.shu.edu/tfp2007/

NEW: Abstract submission is now open! Link: 
http://cs.shu.edu/tfp2007/submissions.html

NEW: Invited Talk: John McCarthy, Standford University
 
 
The symposium on Trends in Functional Programming (TFP) is an 
international forum for researchers with interests in all aspects of 
functional programming languages, focusing on providing a broad view of 
current and future trends in Functional Programming. It aspires to be a 
lively environment for presenting the latest research results through 
acceptance by extended abstracts. A formal post-symposium refereeing 
process then selects the best articles presented at the symposium for 
publication in a high-profile volume. 
TFP 2007 is co-hosted by Seton Hall University and The City College of New 
York (CCNY) and will be held in New York, USA, April 2-4, 2007 at the CCNY 
campus. 

SCOPE OF THE SYMPOSIUM 
 
The symposium recognizes that new trends may arise through various routes. 
As part of the Symposium's focus on trends we therefore identify the 
following five article  categories. High-quality articles are solicited in 
any of these categories: 
 
Research Articlesleading-edge, previously unpublished research 
work
Position Articles  on what new trends should or should not be 
Project Articles   descriptions of recently started new projects 
Evaluation Articles   what lessons can be drawn from a finished 
project
Overview Articles summarizing work with respect to a trendy 
subject
 
Articles must be original and not submitted for simultaneous publication 
to any other forum. They may consider any aspect of functional 
programming: theoretical,  implementation-oriented, or more 
experience-oriented. Applications of functional programming techniques to 
other languages are also within the scope of the symposium. 
 
Articles on the following subject areas are particularly welcomed:
 
o Dependently Typed Functional Programming 
o Validation and Verification of Functional Programs
o Debugging for Functional Languages
o Functional Programming and Security
o Functional Programming and Mobility
o Functional Programming to Animate/Prototype/Implement Systems from 
Formal or Semi-Formal Specifications 
o Functional Languages for Telecommunications Applications
o Functional Languages for Embedded Systems
o Functional Programming Applied to Global Computing
o Functional GRIDs
o Functional Programming Ideas in Imperative or Object-Oriented Settings 
(and the converse)
o Interoperability with Imperative Programming Languages
o Novel Memory Management Techniques
o Parallel/Concurrent Functional Languages
o Program Transformation Techniques 
o Empirical Performance Studies 
o Abstract/Virtual Machines and Compilers for Functional Languages 
o New Implementation Strategies
o any new emerging trend in the functional programming area
 
If you are in doubt on whether your article is within the scope of TFP, 
please contact the TFP 2007 program chair, Marco T. Morazan, at 
[EMAIL PROTECTED]
 
 
SUBMISSION AND DRAFT PROCEEDINGS
 
Acceptance of articles for presentation at the symposium is based on the 
review of extended abstracts (6 to 10 pages in length) by the program 
committee. Accepted  abstracts are to be completed to full papers before 
the symposium for publication in the draft proceedings and on-line. 
Further details can be found at the TFP 2007 website. 
 
 
POST-SYMPOSIUM REFEREEING AND PUBLICATION
 
In addition to the draft symposium proceedings, we intend to continue the 
TFP tradition of publishing a high-quality subset of contributions in the 
Intellect series on Trends in Functional Programming. 
 
IMPORTANT DATES
 
Abstract Submission: February 1, 2007
Notification of Acceptance: February 20, 2007
Registration Deadline: March 2, 2007 
Camera Ready Full Paper Due: March 9, 2007
TFP Symposium: April 2-4, 2007
 
 
PROGRAMME COMMITTEE
 
John Clements   California Polytechnic State University, 
USA 
Marko van Eekelen   Radboud Universiteit Nijmegen, The 
Netherlands 
Benjamin Goldberg   New York University, USA 
Kevin Hammond   University of St. Andrews, UK 
Patricia Johann Rutgers University, USA 
Hans-Wolfgang Loidl Ludwig-Maximilians Universität München, 
Germany 
Rita Loogen Philipps-Universität Marburg, Germany 
Greg Michaelson Heriot-Watt University, UK 
Marco T. Morazán (Chair)Seton Hall University, USA 
Henrik Nilsson  University of Nottingham, UK 
Chris Okasaki   United States Military Academy at West 
Point, USA 
Rex PageUniversity of Oklahoma, USA 
Ricardo PenaUniversidad Complutense de Madrid, Spain 
Benjamin C. Pierce  University of Pennsylvania, USA 
John Reppy  

[Haskell-cafe] seq (was: Article review: Category Theory)

2007-01-19 Thread Brian Hulley

Neil Mitchell wrote:

Hi Brian,

Is there any solution that would allow excess laziness to be removed
from a Haskell program such that Hask would be a category?


class Seq a where
   seq :: a - b - b

Then you have a different seq based on the types, and it doesn't go
wrong. You would probably want deriving Seq support.


This seems an amazingly neat solution to a really terrible problem, so:

1) Does anyone know why this was not used in the first place?

2) Would it be good to use this in future versions of Haskell?

3) Is there any practical program which requires the current seq that could 
not be rewritten to use the typeclass seq?


Thanks, Brian.
--
http://www.metamilk.com 


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


Re: [Haskell-cafe] seq (was: Article review: Category Theory)

2007-01-19 Thread David House

On 19/01/07, Brian Hulley [EMAIL PROTECTED] wrote:

1) Does anyone know why this was not used in the first place?


It was decided that strictness annotations, and optimisations in
general, should typically come after you'd written your program.
However, requiring a Seq context everywhere would change your types,
which is something you don't want to do when you've finished writing
your program.

--
-David House, [EMAIL PROTECTED]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] seq (was: Article review: Category Theory)

2007-01-19 Thread Josef Svenningsson

On 1/20/07, Brian Hulley [EMAIL PROTECTED] wrote:

Neil Mitchell wrote:
 Hi Brian,
 Is there any solution that would allow excess laziness to be removed
 from a Haskell program such that Hask would be a category?

 class Seq a where
seq :: a - b - b

 Then you have a different seq based on the types, and it doesn't go
 wrong. You would probably want deriving Seq support.

This seems an amazingly neat solution to a really terrible problem, so:

1) Does anyone know why this was not used in the first place?


It *was* used before. See section 6.2.7 of the Haskell 1.4 report. It
was throw out in Haskell98. I don't remember why though.


2) Would it be good to use this in future versions of Haskell?

3) Is there any practical program which requires the current seq that could
not be rewritten to use the typeclass seq?


I'll pass on these two questions.

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


[Haskell-cafe] File locked unnecessarily (the continuation)

2007-01-19 Thread Arie Peterson
Hi all,


Some time ago I reported a strange file locking problem. I have reduced my
offending program to a relatively small size.

This reduction process was quite entertaining. At one point, I could
reliably turn the locking off and on by removing and reintroducing a
certain unused import :s. I was happy to see this go away on cutting out
all concurrency.

The example is attached. Open the tarball and run ghc --make Main -O 
./a.out in the resulting directory.

On my system (amd64 Gentoo linux, ghc 6.4.2), this gives the following
output.

##
Chasing modules from: Main
Compiling Interface( ./Interface.hs, ./Interface.o )
Compiling Main ( Main.hs, Main.o )
Linking ...
Compiling plugin P
b
a.out: a.txt: openFile: resource busy (file is locked)
##

There is no reason for the file a.txt to be locked.

The problem is somewhat brittle: any one of the following changes makes it
disappear:

  - in Main.hs:main, replacing the 'c' argument of 'cat' (the one
dynamically loaded from the plugin 'P') by 'Interface.c';
  - in Main.hs:main, removing one of the two 'cat c' calls;
  - in Interface.hs:c, removing one of the two 'a' calls.

Because of the first of these, it seems that the problem is partly caused
by the dynamic linking, but I'm not sure about that (the unused import
experience made me a bit paranoid ;-) ).

Can someone comment on the cause of this locking issue, or maybe further
simplify the example?


Thanks and greetings,

Arie

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


[Haskell-cafe] File locked unnecessarily (the file)

2007-01-19 Thread Arie Peterson
Except that the example was not attached. Sorry.


Greetings,

Arie

min.tar.gz
Description: application/gzip
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Article review: Category Theory

2007-01-19 Thread Lennart Augustsson

No, making $! the primitive would not help.  You can define seq from $!.
I think seq is a suitable primitive, it's just that it ruins nice  
properties.


The original formulation of seq in Haskell was the right one in my  
opinion:

class Eval where
seq :: a - b - b
This way you get a context on anything that uses seq and you can tell
that there is some funny business going on.

-- Lennart

On Jan 19, 2007, at 13:07 , Brian Hulley wrote:


Lennart Augustsson wrote:


On Jan 19, 2007, at 08:05 , [EMAIL PROTECTED] wrote:
Thus, Hask is not a category, at least not as defined in the  
article.

The problem is that (either) morphisms or the morphism composition
('.')
are not internalized correctly in Haskell.




And this is why some of us think that adding polymorphic seq to
Haskell was a mistake. :(


I've often wondered why seq is the primitive and not $!
Would this solve the problem?
Is there any solution that would allow excess laziness to be  
removed from a Haskell program such that Hask would be a category?


Thanks, Brian.
--
http://www.metamilk.com


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


Re: [Haskell-cafe] seq (was: Article review: Category Theory)

2007-01-19 Thread Lennart Augustsson
This solution was used in the first place.  But then some people were  
too lazy

to actually use the Eval (as Seq was called) class, so they wanted
a polymorphic seq.  And so we're in this mess.  And it is a mess,
e.g., the foldr/build transformation ghc uses to fuse list processing
isn't really valid when you have seq.

-- Lennart

On Jan 19, 2007, at 18:09 , Brian Hulley wrote:


Neil Mitchell wrote:

Hi Brian,

Is there any solution that would allow excess laziness to be removed
from a Haskell program such that Hask would be a category?


class Seq a where
   seq :: a - b - b

Then you have a different seq based on the types, and it doesn't go
wrong. You would probably want deriving Seq support.


This seems an amazingly neat solution to a really terrible problem,  
so:


1) Does anyone know why this was not used in the first place?

2) Would it be good to use this in future versions of Haskell?

3) Is there any practical program which requires the current seq  
that could not be rewritten to use the typeclass seq?


Thanks, Brian.
--
http://www.metamilk.com
___
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] Article review: Category Theory

2007-01-19 Thread Steve Downey

One nit and one massive praise.

nit first. in 'the monad laws and their importance' you say given a
monad M and then outline the laws a functor must satisfy to be a
monad. I would find it clearer to say 'a functor M', and then
emphasise the iff relationship between the laws and the functor M.

the praise: footnote 3. the relationship between join and bind is why
monads are useful and interesting for programmers. i haven't seen it
stated more clearly before. i supose because people who know it assume
it. suggestion: don't bury this in a footnote.

On 1/16/07, David House [EMAIL PROTECTED] wrote:

Hey all,

I've written a chapter for the Wikibook that attempts to teach some
basic Category Theory in a Haskell hacker-friendly fashion.

http://en.wikibooks.org/wiki/Haskell/Category_theory

From the article's introduction:

This article attempts to give an overview of category theory, insofar
as it applies to Haskell. To this end, Haskell code will be given
alongside the mathematical definitions. Absolute rigour is not
followed; in its place, we seek to give the reader an intuitive feel
for what the concepts of category theory are and how they relate to
Haskell.

I'd love comments from newcomers and experts alike regarding my
approach, the content, improvements and so on. Of course, it's on the
wikibook, so if you have anything to add (that's not _too_ substantial
otherwise I'd recommend discussion first) then go ahead.

Thanks in advance.

--
-David House, [EMAIL PROTECTED]
___
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