Re: [Haskell-cafe] Re: Functional progr., infinity, and the Universe

2006-06-24 Thread Paul Hudak

Stepan Golosunov wrote:

1:_|_ is certainly finite.


And what is length _|_ ?


_|_, of course!! :-)

The point being, length is well-defined only for total lists; it is 
undefined for partial lists.  But this doesn't mean that a partial list 
isn't finite.


What is "finite list" then?
Is ones = 1:ones also finite?


Hmmm... never tried to write all this down in one place before, but I 
think this covers all cases:


A partial list is one that ends in _|_.
A total list is one that ends in [].
A finite list is either partial or total.
Any other list is infinite.

So "ones" is infinite.

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


Re: [Haskell-cafe] ReadP and MonadFix

2006-06-24 Thread Gracjan Polak

Thanks for your response!

I searched for something more found: An Abstract Monadic Semantics for
Value Recursion, Eugenio Moggi, Amr Sabry

http://citeseer.ist.psu.edu/moggi03abstract.html

Section 4 of this paper says something about References and
Continuations. But it will be quite hard to translate this into actual
code. Could you please point me to the running examples you were
talking about?

I'm going to create MonadFix instance for the P monad and then I'll
see what can I achieve with that.

2006/6/23, Levent Erkok <[EMAIL PROTECTED]>:

Gracjan:

To declare "ReadP" an instance of MonadFix; you'll first have to make the P
monad into a MonadFix instance. That can be done using existing techniques
in the literature.

ReadP is essentially the continuation monad transformer wrapped around P.
It's well known in the value-recursion literature that continuation monad is
too "strong" to have a value-recursion operator. I am not aware of any
"simple" solutions in that space. Hence, ReadP is beyond the realm of
current theories of value recursion.

Having said that, I'd also like to point out that Amr Sabry and Eugenio
Moggi, and independently  Magnus Carlsson has done some interesting work to
extend value recursion to the world of continuations;



which might help with

your particular problem. Essentially, you end up adding some extra
infrastructure to your monad, and then forgo some of the basic axioms of
value recursion. But you can get running examples!

Maybe all you'll need is a MonadFix instance of P; which is definitely
doable with the current techniques. Anything further would actually make a
nice research paper...

-Levent. (I could provide references to above work if needed; all is
available on the net freely, anyhow.)


On 6/23/06, Gracjan Polak <[EMAIL PROTECTED]> wrote:
>
 Hi all,

A question for hot summer day:
Text.ParserCombinators.ReadP.ReadP is
an instance of Monad. Could it be an instance of MonadFix too?

I'm not that sharp in Haskell to write it myself, but it seems I could
make use of such a beast. :) Anybody willing to share?

This will also present the advantage of Lazy over Eager Parser
Combinators, mentioned in some other thread.

--
Gracjan
___
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] Binary IO

2006-06-24 Thread Bulat Ziganshin
Hello jeff,

Saturday, June 24, 2006, 10:19:17 AM, you wrote:

> I would greatly appreciate it if someone could post a small example or two 
> illustrating how to do
> binary IO in Haskell using the most widely used binary IO lib (if
> there is such a thing).  Failing that, I would
> appreciate a link to some Haskell code that does binary IO that I could study.

the most widely used is NewBinary lib. but nevertheless i suggest you
to use my own Streams library. it's close enough to NewBinary in overall
ideology, but simpler, easy to install and may become new standard in
this area because it has innumerous number of features

Download: http://www.haskell.org/library/Streams.tar.gz
Installation: run "make install"

with my lib, binary I/O can be performed using Handles. there
are just a number of new I/O operations what reads and writes words of
specified size:

main = do h <- openBinaryFile "test" ReadMode
  i <- getWord32le h
  j <- getWord8 h
  
  hout <- openBinaryFile "test" WriteMode
  putWord32le hout (1::Int)
  putWord8hout (2::Int)
  ...

you can use all the Handle operations (hSeek, hFilesize and so on) and
even mix binary and text I/O. there are also features to define
operations that read and write whole data structures

library docs are still unfinished. i will send existing bits of
documentation to you via email. i plan to publish final docs at
http://haskell.org/haskellwiki/Library/AltBinary but at this moment
this page contains only feature list


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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