Re: [Haskell-cafe] A handy little consequence of the Cont monad

2008-02-01 Thread Henning Thielemann

On Fri, 1 Feb 2008, Cale Gibbard wrote:

 Hello,

 Today on #haskell, resiak was asking about a clean way to write the
 function which allocates an array of CStrings using withCString and
 withArray0 to produce a new with* style function. I came up with the
 following:

 nest :: [(r - a) - a] - ([r] - a) - a
 nest xs = runCont (sequence (map Cont xs))

 withCStringArray0 :: [String] - (Ptr CString - IO a) - IO a
 withCStringArray0 strings act = nest (map withCString strings)
  (\rs - withArray0 nullPtr rs act)

 Originally, I'd written nest without using the Cont monad, which was a
 bit of a mess by comparison, then noticed that its type was quite
 suggestive.

 Clearly, it would be more generally useful whenever you have a bunch
 of with-style functions for managing the allocation of resources, and
 would like to turn them into a single with-style function providing a
 list of the acquired resources.

Nice idea. Could serve as an explanation what the Cont monad is good for.
What about uploading it to the Wiki Category:Idioms ?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: derive Pretty?

2008-02-01 Thread Christian Maeder
Greg Fitzgerald wrote:
 Is it possible to automatically derive instances of Pretty
 http://haskell.org/ghc/docs/latest/html/libraries/haskell-src/Language-Haskell-Pretty.html?
  
 If no, what do most do when it comes to pretty-printing large data types?

We do it manually. Usually you have to decide anyway which bits to omit
or add (only implicitly indicated by a data constructor) and if you
compose things vertically or beside (or nested or whatever) to make it
look pretty.

HTH Christian

see i.e an abstract syntax at:
http://www.dfki.de/sks/hets/src-distribution/daily/Hets/docs/CASL-AS_Basic_CASL.html

the pretty printer code is here
http://www.dfki.de/sks/hets/src-distribution/daily/Hets/CASL/ToDoc.hs

our pretty printer wrapper (for text and latex tailored for Hets)
http://www.dfki.de/sks/hets/src-distribution/daily/Hets/docs/Common-Doc.html

(try versions instead of daily, if a daily went wrong)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] anybody can tell me the pronuncation of haskell?

2008-02-01 Thread Benjamin L. Russell
Here in Japan, it's pronounced in four syllables with
no accent, as follows:

Hah (as in Hah, I see.)

Sue (as in the name)

Ke (as in the first syllable of ketchup)

Ru (as in the first syllable of Lucas, since there
is no difference between l and r sounds in
Japanese)

Put together, it sounds as follows:

Hah-Sue-Ke-Ru

Here's the URL of the Japanese Wikipedia page for
Haskell Curry (for those who can read Japanese):

http://ja.wikipedia.org/wiki/%E3%83%8F%E3%82%B9%E3%82%B1%E3%83%AB%E3%83%BB%E3%82%AB%E3%83%AA%E3%83%BC

Benjamin L. Russell

--- Paulo Tanimoto [EMAIL PROTECTED] wrote:

 On Jan 29, 2008 11:19 AM, Jeremy Apthorp
 [EMAIL PROTECTED] wrote:
  Another Japanese word adopted from Portuguese is
 their word for bread: pan.
 
 tabako too, I believe (it's not even written in
 katakana).
 
 Now, how do the Japanese pronounce Haskell, I'd like
 to know.
 
 Paulo
 ___
 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] Announce: CC-delcont 0.2

2008-02-01 Thread Dan Doel
Hello all,

After much distraction and laziness on my part (my apologies), I have finally 
gotten around to putting together a new release of the delimited 
continuations library CC-delcont. It is now available on hackage.

Relevant changes include:

* Now builds in GHC-6.8.x
* Builds with -Wall (and the code was cleaned up to make as little noise
   as possible)
(Thanks to gwern for the above)

Also included is a new module, Control.Monad.CC.Cursor, which provides some 
functions for reifying traversals into cursors that can be passed around and 
manipulated. It's still in its infancy, but I hope to eventually include 
generalized zippers and such.

GHC 6.8 or greater is required to build, and haddock 2.0 or greater is 
required to generate the documentation.

Links:

* hackage: 
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/CC-delcont-0.2
* darcs: http://code.haskell.org/~dolio/CC-delcont/
* a brief tutorial: http://haskell.org/haskellwiki/Library/CC-delcont
   (I've not had too much feedback on this, so if anyone has trouble
following some sections, or has ideas on how to better explain
delimited continuations, changes are welcome.)

Once again, if you discover any bugs, or have any suggestions, don't hesitate 
to let me know.

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


[Haskell-cafe] Data.Ord and Heaps (Was: Why functional programming matters)

2008-02-01 Thread apfelmus

Stephan Friedrichs wrote:

apfelmus wrote:

[...]
Feedback: I think the HeapPolicy thing is too non-standard. The  
canonical way would be to use a MinHeap and let the Ord instance  
handle everything. A MaxHeap can then be obtained via a different  
Ord instance

   newtype Ord a = Reverse a = Reverse { unReverse :: a }
   instance Ord a = Ord (Reverse a) where
 compare = comparing unReverse
This newtype should be in Data.Ord, of course. Being


This solution should be used for all collections depending on Ord  
instances, including Data.Map, Data.Set and others. As long as I  
only include it in my tiny heap package, it is as 'non-standard' as  
my approach, isn't it?


Yes. I mean non-standard in the software-reuse sense, i.e. Ord is  
for user-defined orderings and should be the only such mechanism in  
order to enable reuse. In fact, Data.Heap clearly shows that Data.Ord  
is currently missing functionality.



Simply setting
  type MaxHeap a = MinHeap (Reverse a)
is inferior to a native MaxHeap since we'd have to pack/unpack  
the Reverse  all the time. But a type class for heaps - which  
should be present anyway - can solve that problem:

  class Heap h where
[...]
  instance Heap MinHeap where ...
  newtype MaxHeap a = M (MinHeap (Reverse a))
  instance Heap MaxHeap where ...


I've actually thought about this. Realising MinHeap and MaxHeap is  
no problem, but I decided against it, because implementing a custom  
order becomes quite complicated: You have to declare an


newtype MyHeap a = ...

instance Heap MyHeap where
-- about 10 functions

instead of just

data PriorityPolicy

instance HeapPolicy PP MyPriorityType where
heapCompare = const (comparing priority)


Note that the Heap class contains only three primitive operations  
(empty, insert, viewHead), all the others have default  
implementations in terms of those three. There is even an  
underappreciated unfold among them :)


  toAscList = unfoldr viewHead

The structure becomes especially clear by noting that any Heap is  
defined by just two primitives


  inject :: Ord a = Maybe (a, Heap a) - Heap a
  view   :: Ord a = Heap a - Maybe (a, Heap a)

We have  inject = maybe empty (uncurry insert)  . This is just like  
lists, except that  view . inject ≠ id   since  view  returns the  
smallest element.



However, just that we managed to reduce the number of primitive  
operations doesn't mean that the policy approach isn't preferable. It  
needs 0 primitive operations, after all. But as foreshadowed in my  
reply, it's possible to do policies within Ord. Don't stop thinking  
about your good idea just because you can start coding :)


Here's one way to do it:

   module Data.Ord where
 ...
 class (Ord p a) = OrdPolicy p a where   -- the policy p is a  
type constructor

to   :: a - p a
from :: p a - a

 instance OrdPolicy Identity a where ...

 newtype Reverse a = Reverse a
 instance Ord a = Reverse a where
compare = flip $ comparing from
 instance OrdPolicy Reverse a where
to = Reverse; from (Reverse x) = x

   module Data.Heap where
 ...
 newtype Heap p a = Heap (MinHeap (p a))
 type MaxHeap a   = Heap Reverse a

 class Ord a = Heap h a | h - a where
   empty:: h
   insert   :: a - h - h
   viewHead :: h - Maybe (a, h)

 instance OrdPolicy p a = Heap (Heap p a) a where
...

What I don't like about this is that the policy is not polymorphic in  
the element types, forcing the Heap class to be multi-parameter. I'd  
really like to write


  class (forall a . Ord p a) = OrdPolicy p where

but I guess that's (currently) not possible. The original phantom  
policy approach can't quite do this either:


   module Data.Ord where
 ...
 newtype OrdBy p a = OrdBy { unOrdBy :: a }

 data Reverse
 instance Ord a = Ord (OrdBy Reverse a) where
compare = flip $ comparing unOrdBy

   module Data.Heap where
 ...
 newtype Heap p a = Heap (MinHeap (OrdBy p a))
 type MaxHeap a   = Heap Reverse a

 class Heap h where
   empty:: Ord a = h a
   insert   :: Ord a = a - h a - h a
   viewHead :: Ord a = h a - Maybe (a, h a)

 instance (Ord (OrdBy p a)) = Heap (Heap p) where   -- forall a?
...

However, a distinct advantage of using OrdBy for all ordering  
policies is that the  from  and  to  functions are no longer  
necessary. All ordering policies use the same type  OrdBy  which  
automatically guarantees that  from  and  to  are inverse to each  
other. This would be an informal requirement otherwise, so I think  
that phantom policies are clearly superior to type constructor  
policies. Fortunately, this is orthogonal to making Heap a multi- 
parameter type class and ensuring that  OrdBy p a  instances are  
polymorphic in  a  .



In conclusion: the ordering policy stuff should not be part of  
Data.Heap, this is a job for Data.Ord.
As mentioned above: This sounds really 

Re: [Haskell-cafe] Re: hxt memory useage

2008-02-01 Thread Malcolm Wallace
Rene de Visser [EMAIL PROTECTED] wrote:

 Even if you replace parsec, HXT is itself not
 incremental.  (It stores the whole XML document in memory as a tree,
 and the tree is not  memory effecient.

If the usage pattern of the tree is search-and-discard, then only enough
of the tree to satisfy the search needs to be stored in memory at once.
Everything from the root to the first node of interest can easily be
pruned by the garbage collector.

A paper describing the lazy parsing technique, and using XML-parsing as
its motivating example, is available at
http://www.cs.york.ac.uk/~malcolm/partialparse.html

  haxml offers the choice of non-incremental parsers and incremental
  parsers.

Indeed.  This lazy incremental parser for XML is available in the
development version of HaXml:
http://www.cs.york.ac.uk/fp/HaXml-devel

The source code for partial parsing is available in a separate package:
http://www.cs.york.ac.uk/fp/polyparse

These lazy parser combinators are roughly between 2x - 5x faster than
Parsec on large inputs (although the strict variation is about 2x slower
than Parsec).

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


Re: [Haskell-cafe] Re: anybody can tell me the pronuncation of?haskell?

2008-02-01 Thread Benjamin L. Russell
According to the Gogen Yurai Jiten (Etymology
Derivation Dictionary)
(http://gogen-allguide.com/a/arigatou.html), the
etymology of arigato (arigatou when entered into a
Japanese input method editor, such as Kotoeri) is as
follows (at the risk of moji-bake (garbled text), I
have included the Japanese text in Japanese characters
before each translated portion):

- translated text follows immediately after this line
-
‚ ‚肪‚Æ‚¤‚̌ꌹ‚́AŒ`—eŽŒu—L‚è“i‚ ‚肪‚½‚µjv‚̘A—pŒ`u—L‚è“ï‚­i‚ ‚肪‚½‚­jv‚ªƒE‰¹•Ö‰»‚µA‚ ‚肪‚Æ‚¤‚Æ‚È‚Á‚½B

The etymology of arigatou is that the te-form
[loosely translated as conjunctive form] arigataku
of the adjective arigatashi changed in form to end
in the u sound, and became arigatou.

u—L‚è“i‚ ‚肪‚½‚µjv‚́Au—L‚éi‚ ‚éj‚±‚Ɓv‚ªu“ï‚¢i‚©‚½‚¢jv‚Æ‚¢‚¤ˆÓ–¡‚ŁA–{—ˆ‚́u–Å‘½‚É‚È‚¢v‚âu’¿‚µ‚­‚Ä‹Md‚¾v‚Æ‚¢‚¤ˆÓ–¡‚ð•\‚µ‚½B

Arigatashi has the meaning of being being
rare/difficult, and originally expressed the
meaning of rare or uncommon and precious.

w–‘Žqx‚́u‚ ‚肪‚½‚«‚à‚́v‚ł́Au‚±‚̐¢‚É‚ ‚é‚Ì‚ª“‚¢v‚Æ‚¢‚¤ˆÓ–¡A‚‚܂èAu‰ß‚²‚µ‚É‚­‚¢v‚Æ‚¢‚Á‚½ˆÓ–¡‚Å‚à—p‚¢‚ç‚ê‚Ä‚¢‚éB

In [the scene] Arigataki Mono [That Which is
Uncommon/Precious] ] of Makura no Soushi [The Pillow
Book] [see
http://en.wikipedia.org/wiki/The_Pillow_Book], it is
also used to mean it is difficult to be in this
world; i.e., difficult to spend [time in].

[EMAIL PROTECTED]

When medieval times arrived, from [the idea of]
charity of the Buddha, etc., in obtaining that which
is precious and difficult to obtain, it came to
express a feeling of gratitude, and in recent times
and later, it spread to general use as the meaning of
gratitude.

ƒ|ƒ‹ƒgƒKƒ‹Œê‚́uƒIƒuƒŠƒK[ƒhiobrigadojv‚©‚çAu‚ ‚肪‚Æ‚¤v‚ÆŒ¾‚¤‚悤‚É‚È‚Á‚½‚Æ‚¢‚¤‘­à‚ª‚ ‚邪Aƒ|ƒ‹ƒgƒKƒ‹l‚ª–K‚ê‚éˆÈ‘O‚©‚çŽg‚í‚ê‚Ä‚¢‚½Œ¾—t‚ªƒ|ƒ‹ƒgƒKƒ‹Œê‚É—R—ˆ‚·‚é‚Í‚¸‚Í‚È‚­AuƒIƒuƒŠƒK[ƒhv‚Ɓu‚ ‚肪‚Æ‚¤v‚̉¹‚ª‹ß‚¢‚Æ‚¢‚¤‚¾‚¯‚̘b‚ŁA’ö“x‚Ì’á‚¢‘­à‚Å‚ ‚éB

There is a myth that from obrigado of Portuguese,
people came to say arigatou, but it cannot be the
case that a word used before Portuguese people [first]
visited Japan was derived from the Portuguese
language; it just so happens to be the case that the
sounds of obrigado and arigatou are similar, and
this is a vulgar myth.
- translated text ends immediately before this line -

Yoroshiku onegai itashimasu.

Arigatou gozaimasu.

Benjamin L. Russell

--- [EMAIL PROTECTED] wrote:

 Chung-chieh Shan corrects me: 
 
  PS. If you think that arigato is a genuine
 Japanese word, well, check
  how the appropriately translated word is spelled
 in Portuguese... 
  
  I'm not sure what you mean by genuine, but I
 suspect that whether
  arigato is genuine does not depend on
 Portuguese.
  http://linguistlist.org/issues/12/12-1871.html
  http://linguistlist.org/issues/12/12-1906.html
  
 
 Yes, it seems that I have been one more victim of
 this red herring.
 In the cited issues of the linguistlist there is a
 nice discussion of that
 topic. It should be more widely known entre a gente
 falando portugues.
 Vou calar a boca... 
 
 Gomen nasai. 
 
 Jerzy Karczmarczuk 
 
 
 ___
 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] Cabal, GHC, FFI and Visual Studio on Windows

2008-02-01 Thread Magnus Therning
Is it possible to get Cabal to use 'cl' (Microsoft's C/C++ compiler
shipped with Visual Studio Express)?

I've found the Wiki page on using Visual Studio to create a DLL, then
convert it to a .a file so that GHC can consume it.  I'd rather skip
using Visual Studio to build things and just ship a Cabalised package.

/M

-- 
Magnus Therning (OpenPGP: 0xAB4DFBA4)
magnus@therning.org Jabber: magnus.therning@gmail.com
http://therning.org/magnus

What if I don't want to obey the laws? Do they throw me in jail with
the other bad monads?
 -- Daveman



signature.asc
Description: OpenPGP digital signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Implementing fixed-sized vectors (using datatype algebra?)

2008-02-01 Thread Alfonso Acosta
On Jan 31, 2008 11:35 PM, Wolfgang Jeltsch [EMAIL PROTECTED] wrote:
 Am Donnerstag, 31. Januar 2008 18:30 schrieb Dominic Steinitz:
  Look at
 
  http://sneezy.cs.nott.ac.uk/fun/feb-07/jeremy-slides.pdf

 This is essentially what I had in mind.  While Oleg's implementation needs
 a thrusted core, the GADT solution doesn't.

True. However using GADTs doesn't allow to internally make use of
Arrays, which (tell me if I'm wrong) are likely to be faster than the
naive GADT implementation.

Actually the GADT implementation you proposed fits nicely with the
Vector definition already used in my EDSL (it is isomorphic actually),
but efficiency could be an issue.

 Some words on the representation of decimal numbers as types. While the
 representation with types of the form D1 (D2 (D3 Sz)) has the advantage of
 allowing numbers of arbitrary size, it has the disadvantage of a growing
 number of parantheses.  In my opinion, it would be nicer to have somethink
 like D1 :- D2 :- D9 :- () with a right-associative operator :-.  We could
 even build the digit list the other way round—() :- D1 :- D2 :- D9—using a
 left-associative :-.  With the latter representation, we wouldn't need to
 reverse digit sequences when adding numbers.

Right, I agree. I think we should use the arbitrary-size
implementation (actually, how arbitrary is it? what's the limit of
GHC, if any?).

To make it friendlier for the end user I thought about defining
aliases for lets say the first 1 numbers using Template Haskell.
That could even make error reports friendlier (not sure to what point
though). What do you think?


So, we'll be making two separate libraries then. We should think about names.

What about FixedVector for the vector library and DecTypArith (maybe
too long) or DecTypes for the type-level decimal arithmetic library?

I'll put my hands dirty once we agree on this.

Cheers,

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


Re: [Haskell-cafe] Re: Implementing fixed-sized vectors (using datatype algebra?)

2008-02-01 Thread Alfonso Acosta
 What about FixedVector for the vector library and DecTypArith (maybe
 too long) or DecTypes for the type-level decimal arithmetic library?

Actually it would maybe be better to create common high-level
interface that could include unary, binary and decimal arithmetic so
that the library could be easily reused in other projects (people like
Bjorn, seem to be using the unary implementation). I don't know if it
would be feasible though.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Simple network client

2008-02-01 Thread Jules Bean

Jonathan Cast wrote:

On 31 Jan 2008, at 1:23 AM, Reinier Lamers wrote:


Bayley, Alistair wrote:
More than one person has posted previously about the flaws and traps 
of lazy IO. A common position seems to be don't do lazy IO.


Still, when I was browsing the Haskell' wiki a few days ago, I 
couldn't find any proposal to remove lazy I/O or move it into some 
special System.IO.Lazy (or 
System.IO.UnsafeEvilFunctionsThatSacrificeBabies) ...


Sacrificing babies is not a unique characteristic of lazy IO, of course; 
it's true of any file IO on a non-versioning file system.



However you can contain the pain if it's in the IO monad, and be in no 
worse situation than conventional languages.


If the pain is unsafeInterleaved all over the place, then you actually 
*are* in a worse situation.


ObHaskell' : lazy IO shouldn't be in any haskell standard, since it's 
not referentially transparent. It should be a powerful but dangerous 
feature enabled by certain implementations in an implementation specfic 
way. (unsafeInterleaveIO itself is not haskel98, I'm fairly sure)


Jules

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


Re: Cryptographic hash uniquness (was [Haskell-cafe] Simple network client)

2008-02-01 Thread Richard Kelsall

Bulat Ziganshin wrote:

Hello Peter,

Thursday, January 31, 2008, 8:01:36 PM, you wrote:


files with different content generating the same hash)... My
intuition told me that the odds of two cryptographic hashes (on
meaningful content) colliding was much less than the earth being
destroyed by an asteroid... But this is just intuition... What does
computer science tell us about this?


you may be interested to know that widely used rsync algorithms relies
on 128-bit hashes and its author speculated about its reliability:

http://samba.org/~tridge/phd_thesis.pdf



Interesting paper. Thank you. I had a quick read of the bit relating to
hashes and my understanding is this. He uses a weak, quick and simple
hash to deal with 99.99% (I invented that percentage) of cases - if the
hash is different we know the files are definitely different - if the
hash collides he then does a strong, slow, secure hash and relies on
this as the answer. But he's relying on the strong hash rather than
doing a byte by byte comparison because there is a major cost (a network
transmission of the file) to doing the proper byte by byte comparison.
If you had both files accessible at a low cost it might be better to
byte by byte compare them when you get a collision rather than use
the strong hash.

The right approach may be to assume that collisions will occur and
cater for this properly in the program somehow. A good tip for testing
this sort of thing is to have the length of the hash (maximum size of
the array or whatever you want to test) as a parameter that you can
turn down to a very low value to induce collisions (overflows etc) to
see whether the program still works. And then turn it back up for live
use.

A cryptographic hash appears as a completely random function of the
input so the likelihood of a collision is simply 2^(bits in hash).


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


[Haskell-cafe] Who started 42, and when?

2008-02-01 Thread Loup Vaillant
I have read quite a lot of Haskell papers, lately, and noticed that
the number 42 appeared quite often, in informal tutorials as well as
in very serious research papers. No wonder Haskell is the Answer to
The Great Question of Life, The Universe, and Everything, but I would
like to know who started this, and when.

Google wasn't much help, and I can't believe it's coincidence --hence
this email. I hope I didn't opened some Pandora box. :-)

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


Re: [Haskell-cafe] Who started 42, and when?

2008-02-01 Thread Janis Voigtlaender

Denis Bueno wrote:

On Fri, Feb 1, 2008 at 9:03 AM, Loup Vaillant [EMAIL PROTECTED] wrote:


I have read quite a lot of Haskell papers, lately, and noticed that
the number 42 appeared quite often, in informal tutorials as well as
in very serious research papers. No wonder Haskell is the Answer to
The Great Question of Life, The Universe, and Everything, but I would
like to know who started this, and when.



I believe it was Douglas Adams, author of the trilogy Hitchhiker's
Guide to the Galaxy.  You may enjoy reading it, if you haven't.


I think Loup is aware of the hitchhiker books (see the reference to the 
Great Question of ... Everything).


So unless Douglas Adams wrote some Haskell papers I am not aware of, the 
original question is still open ;-)


Happy weekend...
Janis.

--
Dr. Janis Voigtlaender
http://wwwtcs.inf.tu-dresden.de/~voigt/
mailto:[EMAIL PROTECTED]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] fast graph algorithms without object identities

2008-02-01 Thread Alfonso Acosta
You'd probably be interested to read
http://www.cs.chalmers.se/~koen/pubs/entry-asian99-lava.html

On Jan 31, 2008 9:56 PM, Jan-Willem Maessen [EMAIL PROTECTED] wrote:

 On Jan 31, 2008, at 5:39 AM, Henning Thielemann wrote:

 
  It seems that algorithms on graphs can be implemented particularly
  efficient in low-level languages with pointers and in-place updates.
  E.g.
  topological sort needs only linear time, provided that dereferencing
  pointers requires constant time. I could simulate pointer
  dereferencings
  and pointer updates by Map yielding linear logarithmic time for
  topological sort. I wonder if it is possible to write a linear time
  topological sort using lazy evaluation, since the runtime system of
  Haskell implementations is a graph processor based on pointers.

 If so, I'd love to see this written up; I think it may be publishable
 if it isn't published already.

 Note that even using ST techniques can take more than linear time,
 given an arbitrary purely-functionally-defined graph as input.  We
 can't (eg) assume that each node contains a reference, or that they
 are densely numbered, so we end up having to look them up in some
 fashion (though using a hash table can be reasonably quick if we
 uniquely number nodes).

 -Jan-Willem Maessen


 
  ___
  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


Re: [Haskell-cafe] Who started 42, and when?

2008-02-01 Thread Phil Molyneux
Hi --- The arbitrary constant was made popular by Douglas Adams in  
the mid-1970s radio series ``A Hitchhikers Guide to the Galaxy'' (a  
trilogy in 4 parts) --- however it does have a basis in the standard  
model of physics --- a paper in Phys.Rev. of the early 1970s  
described the unification of the Electro-Weak and Strong nuclear  
forces --- the arbitrary constant (of nearly) 42 appears in the  
calculations. I forget the original paper but if you get hold of  
Frank Close ``The Cosmic Onion'' a graph reproduces the result. I met  
Douglas Adams once at a book signing and asked him how he got hold of  
the Phys.Rev. paper so early. Technically he should have written that  
``42 is the answer to life, the universe and everything except for  
gravity and a few other arbitrary constants''


Adams was interested in computing --- I think his reaction to being  
told about functional programming was to wonder what non-functional  
programming might be.


Phil

On 1 Feb 2008, at 14:03, Loup Vaillant wrote:


I have read quite a lot of Haskell papers, lately, and noticed that
the number 42 appeared quite often, in informal tutorials as well as
in very serious research papers. No wonder Haskell is the Answer to
The Great Question of Life, The Universe, and Everything, but I would
like to know who started this, and when.

Google wasn't much help, and I can't believe it's coincidence --hence
this email. I hope I didn't opened some Pandora box. :-)

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

This email has been scanned for all viruses by the MessageLabs Email
Security System.



This email has been scanned for all viruses by the MessageLabs Email
Security System.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Who started 42, and when?

2008-02-01 Thread Christopher L Conway
On Feb 1, 2008 9:27 AM, Loup Vaillant [EMAIL PROTECTED] wrote:
 I suspected this. Just that I didn't noticed 42 but in Haskell papers.
 Maybe this is just a bias due to my recent interests. I should check
 some C/C++/Lisp/Ocaml papers.

 About the library search, Maybe it is possible to try a giant grep
 on all papers in ACM Portal, or CiteSeer?

I tried this briefly on the ACM. You need to be able to exclude
citations, footnotes, volume numbers, etc., and their Advanced
Search is not quite that advanced. :-)

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


Re: [Haskell-cafe] Who started 42, and when?

2008-02-01 Thread Denis Bueno
On Fri, Feb 1, 2008 at 9:03 AM, Loup Vaillant [EMAIL PROTECTED] wrote:
 I have read quite a lot of Haskell papers, lately, and noticed that
  the number 42 appeared quite often, in informal tutorials as well as
  in very serious research papers. No wonder Haskell is the Answer to
  The Great Question of Life, The Universe, and Everything, but I would
  like to know who started this, and when.

I believe it was Douglas Adams, author of the trilogy Hitchhiker's
Guide to the Galaxy.  You may enjoy reading it, if you haven't.

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


Re: [Haskell-cafe] Who started 42, and when?

2008-02-01 Thread Denis Bueno
On Fri, Feb 1, 2008 at 9:19 AM, Janis Voigtlaender
[EMAIL PROTECTED] wrote:
  I think Loup is aware of the hitchhiker books (see the reference to the
  Great Question of ... Everything).

Ah, I didn't read that correctly.  I assumed that something he read
something that had described Haskell as the answer to Life, the
Universe, and Everything.

Sorry about that.

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


Re: [Haskell-cafe] Who started 42, and when?

2008-02-01 Thread Loup Vaillant
2008/2/1, Christopher L Conway [EMAIL PROTECTED]:
 Loup,

 This is not unique to the Haskell community. I suspect the arbitrary
 constant 42 has been appearing unexplained in research papers for as
 long as there have been computer scientists who were sci-fi geeks
 (absolutely no offense intended to geeks ;-). It would be very
 difficult indeed to figure out who did this first, without some highly
 dedicated library research.

I suspected this. Just that I didn't noticed 42 but in Haskell papers.
Maybe this is just a bias due to my recent interests. I should check
some C/C++/Lisp/Ocaml papers.

About the library search, Maybe it is possible to try a giant grep
on all papers in ACM Portal, or CiteSeer?

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


Re: [Haskell-cafe] Who started 42, and when?

2008-02-01 Thread Christopher L Conway
Loup,

This is not unique to the Haskell community. I suspect the arbitrary
constant 42 has been appearing unexplained in research papers for as
long as there have been computer scientists who were sci-fi geeks
(absolutely no offense intended to geeks ;-). It would be very
difficult indeed to figure out who did this first, without some highly
dedicated library research.

Chris

On Feb 1, 2008 9:03 AM, Loup Vaillant [EMAIL PROTECTED] wrote:
 I have read quite a lot of Haskell papers, lately, and noticed that
 the number 42 appeared quite often, in informal tutorials as well as
 in very serious research papers. No wonder Haskell is the Answer to
 The Great Question of Life, The Universe, and Everything, but I would
 like to know who started this, and when.

 Google wasn't much help, and I can't believe it's coincidence --hence
 this email. I hope I didn't opened some Pandora box. :-)

 Cheers,
 Loup
 ___
 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] Re: A handy little consequence of the Cont monad

2008-02-01 Thread ChrisK

The bit of a mess that comes from avoiding monads is (my version):

import Foreign.Marshal.Array(withArray0)
import Foreign.Ptr(nullPtr,Ptr)
import Foreign.C.String(withCString,CString)


This uses withCString in order of the supplied strings, and a difference list 
([CString]-[CString]) initialized by id to assemble the [CString].  This is 
the laziest way to proceed.



acquireInOrder :: [String] - (Ptr CString - IO a) - IO a
acquireInOrder strings act =
foldr (\s cs'io'a -
(\cs -
  withCString s (\c - cs'io'a (cs . (c:))
)
)
  )
  (\cs -
 withArray0 nullPtr (cs []) act
  )
  strings
  id


This uses in withCString in reversed order of the supplied strings, and normal 
list ([CString]) initialized by [] to assemble the [CString].  This is not as 
lazy since it needs to go to the end of the supplied list for the first IO action.



acquireInRerverseOrder :: [String] - (Ptr CString - IO a) - IO a
acquireInRerverseOrder strings act =
  foldl (\cs'io'a s -
  (\cs -
withCString s (\c - cs'io'a (c:cs)
  )
  )
)
(\cs -
   withArray0 nullPtr cs act
)
strings
[]



Cale Gibbard wrote:

Hello,

Today on #haskell, resiak was asking about a clean way to write the
function which allocates an array of CStrings using withCString and
withArray0 to produce a new with* style function. I came up with the
following:

nest :: [(r - a) - a] - ([r] - a) - a
nest xs = runCont (sequence (map Cont xs))

withCStringArray0 :: [String] - (Ptr CString - IO a) - IO a
withCStringArray0 strings act = nest (map withCString strings)
 (\rs - withArray0 nullPtr rs act)

Originally, I'd written nest without using the Cont monad, which was a
bit of a mess by comparison, then noticed that its type was quite
suggestive.

Clearly, it would be more generally useful whenever you have a bunch
of with-style functions for managing the allocation of resources, and
would like to turn them into a single with-style function providing a
list of the acquired resources.

 - Cale


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


Re: [Haskell-cafe] Who started 42, and when?

2008-02-01 Thread Tim Chevalier
To pre-empt the next couple of questions, the numbers 17 and 23 are
from _The Illuminatus! Trilogy_ by Robert Shea and Robert Anton
Wilson, and the number 37 is from the Jersey Trilogy of movies by
Kevin Smith.

Cheers,
Tim

-- 
Tim Chevalier * http://cs.pdx.edu/~tjc * Often in error, never in doubt
I'm a nonbeliever, but I believe in your smile. -- Laura Nyro
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Who started 42, and when?

2008-02-01 Thread Colin Paul Adams
 Phil == Phil Molyneux [EMAIL PROTECTED] writes:

Phil Adams was interested in computing --- I think his reaction
Phil to being told about functional programming was to wonder
Phil what non-functional programming might be.

Curiously, that was my reaction too when i first heard of the term
(from a university student who was complaining that it was too hard).
-- 
Colin Adams
Preston Lancashire
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] fast graph algorithms without object identities

2008-02-01 Thread Jan-Willem Maessen


On Feb 1, 2008, at 9:41 AM, Alfonso Acosta wrote:


You'd probably be interested to read
http://www.cs.chalmers.se/~koen/pubs/entry-asian99-lava.html


It is indeed an interesting paper (that I've read and referred to  
several times over the years).  But it's tricky to get right in  
practice!  And sadly, while it solves the problem of sharing (or  
object equivalence) it doesn't give us some sort of total order or  
hash key, so there's no way to efficiently associate transient mutable  
state uniquely with each reference we encounter.  For that we need one  
of the other solutions discussed and rejected.  This is why  
Data.Unique provides a pure hashUnique function.


The best option I know of here to get the desired time bounds with a  
purely-functional abstraction is to use a splittable supply of unique  
labels (which can be encapsulated in a monad if we like), then use ST  
to associate a hash table of references with the graph nodes while  
traversing the graph.


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


[Haskell-cafe] Re: Implementing fixed-sized vectors (using datatype algebra?)

2008-02-01 Thread Aaron Denney
On 2008-02-01, Bjorn Buckwalter [EMAIL PROTECTED] wrote:
 If Naturals had been sufficient for me I wouldn't have done my own
 implementation (I'm unaware of any other implementation of Integers).
 And there is certainly a lot of value to the clearer error messages
 from a decimal representation.

I did a balanced-base-three (digits are 0, and +- 1) representation to
get negative decimals.  Again, for a proof-of-concept dimensional
analysis arithmetic.  No problem with the stack, but the error messages
are still less than clear.

-- 
Aaron Denney
--

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


Re: [Haskell-cafe] reading from the cdrom drive on Red Hat

2008-02-01 Thread Adam Langley
2008/2/1 Galchin Vasili [EMAIL PROTECTED]:
   I wrote a simple program to read the contents of a cdrom:

(Note that this is a terribly inefficient way of reading large amounts
of binary data. Of course, if this is just meant as an example, that's
fine. Otherwise, see the struff about ByteStrings at
http://www.haskell.org/haskellwiki/DealingWithBinaryData)

The error you are seeing comes from the operating system. You could
run the resulting Haskell program under strace to see the exact error,
but what's happening is that the kernel is getting an error from the
CD drive itself. This is pretty much unique to CDs I guess. If you
were reading a hard drive, the kernel knows exactly how large the disk
is (see /proc/partitions) and would return EOF (zero bytes).

As an aside, hitting EOF in your code would result in an infinite
loop, since you don't handle actualByteCount == 0.

You can catch and handle the resulting exception with the functions in:
  http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.html



AGL


-- 
Adam Langley  [EMAIL PROTECTED]
http://www.imperialviolet.org   650-283-9641
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] reading from the cdrom drive on Red Hat

2008-02-01 Thread Galchin Vasili
Hello,

  I wrote a simple program to read the contents of a cdrom:

module Main where

import Text.Printf
import System.IO
import System.Posix.Types
import System.Posix.IO

main = do
fd - openFd /dev/cdrom ReadOnly Nothing defaultFileFlags
readCdRom fd 4096
closeFd fd

readCdRom fd byteCount = do
(buf, actualByteCount) = fdRead fd bytecount
readCdRom fd byteCount

When it executed it read thousands of 4096 blocks as I expected. It then got
a hardware error which I suspect was the end of the CD, i.e. the
begininng of the unlasered part of the CD. Is there a better and more
graceful way to detect and handle end of data?

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


Re: [Haskell-cafe] A handy little consequence of the Cont monad

2008-02-01 Thread Derek Elkins
On Fri, 2008-02-01 at 00:09 -0500, Cale Gibbard wrote:
 Hello,
 
 Today on #haskell, resiak was asking about a clean way to write the
 function which allocates an array of CStrings using withCString and
 withArray0 to produce a new with* style function. I came up with the
 following:
 
 nest :: [(r - a) - a] - ([r] - a) - a
 nest xs = runCont (sequence (map Cont xs))

This is what you write after all that time on #haskell?

nest = runCont . sequence . map Cont

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


Re: [Haskell-cafe] Re: Implementing fixed-sized vectors (using datatype algebra?)

2008-02-01 Thread Wolfgang Jeltsch
Am Freitag, 1. Februar 2008 05:11 schrieben Sie:
 Wolfgang Jeltsch wrote:
  Well, the representation (D1,D2,D9) might be considered more readable. 
  It has the disadvantage of a fixed maximum size for the numbers.  Which
  takes me to a point I had already considered some time ago: Wouldn’t it
  be good if we had just a type
 
  data Pair val1 val2 = Pair val1 val2
 
  and if then (val1,val2,…,valn) would just be syntactic sugar for this:
 
  val1 `Pair` (val2 `Pair` (…(valn `Pair` ())…))

 I've thought of that too.. besides the asymmetry, the presence of
 _|_/seq makes them actually not equivalent though, unfortunately

 ~Isaac

With Ryan’s proposal (using strictness annotations) the new representation 
should be equivalent to the old one.  Or am I missing something?

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


Re: [Haskell-cafe] Re: Implementing fixed-sized vectors (using datatype algebra?)

2008-02-01 Thread Wolfgang Jeltsch
Am Freitag, 1. Februar 2008 13:09 schrieben Sie:
  What about FixedVector for the vector library and DecTypArith (maybe
  too long) or DecTypes for the type-level decimal arithmetic library?

 Actually it would maybe be better to create common high-level
 interface that could include unary, binary and decimal arithmetic so
 that the library could be easily reused in other projects (people like
 Bjorn, seem to be using the unary implementation). I don't know if it
 would be feasible though.

I’d say, let’s start with the decimal thing.  We can extend our package later 
if there’s a need to do this, can’t we?

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


Re: [Haskell-cafe] reading from the cdrom drive on Red Hat

2008-02-01 Thread Galchin Vasili
Thank you Adam and Bradley. My program is my getting a feel of how to open a
Linux and do block reads. Just conceptual

Vasili


On 2/1/08, Adam Langley [EMAIL PROTECTED] wrote:

 On Feb 1, 2008 1:42 PM, Bryan O'Sullivan [EMAIL PROTECTED] wrote:
  No, it's the Haskell runtime turning a -1 return from read into an
  exception.  You need to call hIsEOF to check whether you've hit EOF,
  then break out of the loop.

 (assuming you meant 0, not -1)

 My bad, I thought that the Posix.IO stuff was a closer wrapping than
 that. It does, indeed, throw an exception on 0. How unfortunate.


 AGL


 --
 Adam Langley  [EMAIL PROTECTED]
 http://www.imperialviolet.org   650-283-9641

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


Re: [Haskell-cafe] Re: Implementing fixed-sized vectors (using datatype algebra?)

2008-02-01 Thread Wolfgang Jeltsch
Am Freitag, 1. Februar 2008 13:00 schrieb Alfonso Acosta:
 On Jan 31, 2008 11:35 PM, Wolfgang Jeltsch [EMAIL PROTECTED] 
wrote:
  Am Donnerstag, 31. Januar 2008 18:30 schrieb Dominic Steinitz:
   Look at
  
   http://sneezy.cs.nott.ac.uk/fun/feb-07/jeremy-slides.pdf
 
  This is essentially what I had in mind.  While Oleg's implementation
  needs a thrusted core, the GADT solution doesn't.

 True. However using GADTs doesn't allow to internally make use of
 Arrays, which (tell me if I'm wrong) are likely to be faster than the
 naive GADT implementation.

It depends.  My first GADT implementation is equivalent to the [] type and 
often [] is better than arrays.  For example, if you read the contents of a 
file and process it with maps, filters, etc., [] is likely to give you 
constant space usage which arrays don’t.  If you want to lookup elements by 
index, then arrays are better, of course.  For my purpose, it would be fine 
to use a []-like implementation, I think.

 […]

  Some words on the representation of decimal numbers as types. While the
  representation with types of the form D1 (D2 (D3 Sz)) has the advantage
  of allowing numbers of arbitrary size, it has the disadvantage of a
  growing number of parantheses.  In my opinion, it would be nicer to have
  somethink like D1 :- D2 :- D9 :- () with a right-associative operator :-.
   We could even build the digit list the other way round—() :- D1 :- D2 :-
  D9—using a left-associative :-.  With the latter representation, we
  wouldn't need to reverse digit sequences when adding numbers.

 Right, I agree. I think we should use the arbitrary-size implementation

So let’s use the representation with the left-associative :- (or whatever 
operator we might choose).

 (actually, how arbitrary is it? what's the limit of GHC, if any?).

Arbitrary enough, I think.  If we don’t need lists with billions of elements, 
our representations will have less than 8 digits.

 To make it friendlier for the end user I thought about defining
 aliases for lets say the first 1 numbers using Template Haskell.
 That could even make error reports friendlier (not sure to what point
 though). What do you think?

I have no clear opinion about that at the moment.  Maybe it’s okay to use the 
representation directly.  This way, we don’t introduce a dependeny on the 
Template Haskell language extension (which is only supported by GHC), and the 
actual representation will occur in error messages anyway whenever the 
message shows a computed number.

 So, we'll be making two separate libraries then. We should think about
 names.

 What about FixedVector for the vector library and DecTypArith (maybe
 too long) or DecTypes for the type-level decimal arithmetic library?

Alas, there is an inconsistency in naming packages already.  Some prefer names 
which are entirely lowercase, some prefer camel case.  I prefer lowercase, 
with hyphens separating parts of the name.  And I also don’t like unusual 
abbreviations like “typ” (not much shorter than “type”).  To mention 
arithmetics is not so important.  So maybe something 
like “type-level-decimals”?

Maybe it’s better to put different type-level programming things into a single 
package.  Then we could name this package “type-level” or something similar.  
We could start with our decimals.  Other type-level things could be added 
later.  I already have some code about type-level booleans.  It’s not very 
sensible to put these few lines into a separate package.  It might be nice if 
we had a general type-level programming package where I could put this code 
into.

As for the name of the fixed-size list package, I have to say that I don’t 
like the term “vector” in this context.  A vector is actually something with 
addition and scalar multiplication defined on it.  Maybe we should make also 
this package’s scope wider.  What about something like “safe-data” or 
similar?

 I'll put my hands dirty once we agree on this.

Great!!

 Cheers,

 Fons

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


Re: [Haskell-cafe] reading from the cdrom drive on Red Hat

2008-02-01 Thread Bryan O'Sullivan
Adam Langley wrote:

 The error you are seeing comes from the operating system.

No, it's the Haskell runtime turning a -1 return from read into an
exception.  You need to call hIsEOF to check whether you've hit EOF,
then break out of the loop.

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


Re: [Haskell-cafe] A handy little consequence of the Cont monad

2008-02-01 Thread Dan Licata
Not to start a flame war or religious debate, but I don't think that
eta-expansions should be considered bad style.  I realize that
composition-style is good for certain types of reasoning, but fully
eta-expanded code has an important legibility advantage: you can tell
the shape of its type just by looking at it!  Personally, I'd rather
read the original version.

-Dan

On Feb01, Derek Elkins wrote:
 On Fri, 2008-02-01 at 00:09 -0500, Cale Gibbard wrote:
  Hello,
  
  Today on #haskell, resiak was asking about a clean way to write the
  function which allocates an array of CStrings using withCString and
  withArray0 to produce a new with* style function. I came up with the
  following:
  
  nest :: [(r - a) - a] - ([r] - a) - a
  nest xs = runCont (sequence (map Cont xs))
 
 This is what you write after all that time on #haskell?
 
 nest = runCont . sequence . map Cont
 
 ___
 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] reading from the cdrom drive on Red Hat

2008-02-01 Thread Adam Langley
On Feb 1, 2008 1:42 PM, Bryan O'Sullivan [EMAIL PROTECTED] wrote:
 No, it's the Haskell runtime turning a -1 return from read into an
 exception.  You need to call hIsEOF to check whether you've hit EOF,
 then break out of the loop.

(assuming you meant 0, not -1)

My bad, I thought that the Posix.IO stuff was a closer wrapping than
that. It does, indeed, throw an exception on 0. How unfortunate.


AGL


-- 
Adam Langley  [EMAIL PROTECTED]
http://www.imperialviolet.org   650-283-9641
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] A handy little consequence of the Cont monad

2008-02-01 Thread Lennart Augustsson
It's a matter of taste.  I prefer the function composition in this case.
It reads nicely as a pipeline.

  -- Lennart

On Fri, Feb 1, 2008 at 9:48 PM, Dan Licata [EMAIL PROTECTED] wrote:

 Not to start a flame war or religious debate, but I don't think that
 eta-expansions should be considered bad style.  I realize that
 composition-style is good for certain types of reasoning, but fully
 eta-expanded code has an important legibility advantage: you can tell
 the shape of its type just by looking at it!  Personally, I'd rather
 read the original version.

 -Dan

 On Feb01, Derek Elkins wrote:
  On Fri, 2008-02-01 at 00:09 -0500, Cale Gibbard wrote:
   Hello,
  
   Today on #haskell, resiak was asking about a clean way to write the
   function which allocates an array of CStrings using withCString and
   withArray0 to produce a new with* style function. I came up with the
   following:
  
   nest :: [(r - a) - a] - ([r] - a) - a
   nest xs = runCont (sequence (map Cont xs))
 
  This is what you write after all that time on #haskell?
 
  nest = runCont . sequence . map Cont
 
  ___
  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


Re: [Haskell-cafe] A handy little consequence of the Cont monad

2008-02-01 Thread Derek Elkins
On Fri, 2008-02-01 at 16:48 -0500, Dan Licata wrote:
 Not to start a flame war or religious debate, but I don't think that
 eta-expansions should be considered bad style.  I realize that
 composition-style is good for certain types of reasoning, but fully
 eta-expanded code has an important legibility advantage: you can tell
 the shape of its type just by looking at it!  Personally, I'd rather
 read the original version.

Clearly you don't hang out on #haskell enough and have missed the humor.

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


Re: [Haskell-cafe] A handy little consequence of the Cont monad

2008-02-01 Thread Conor McBride

Folks

On 1 Feb 2008, at 22:19, Lennart Augustsson wrote:

It's a matter of taste.  I prefer the function composition in this  
case.

It reads nicely as a pipeline.

  -- Lennart



Dan L :



On Fri, Feb 1, 2008 at 9:48 PM, Dan Licata [EMAIL PROTECTED] wrote:
Not to start a flame war or religious debate, but I don't think that
eta-expansions should be considered bad style.


Cale:


  nest :: [(r - a) - a] - ([r] - a) - a
  nest xs = runCont (sequence (map Cont xs))



Derek:


 This is what you write after all that time on #haskell?

 nest = runCont . sequence . map Cont


Pardon my voodoo (apologies to libraries readers,
but here we go again, slightly updated).

With these useful general purpose goodies...

 module Newtype where

 import Data.Monoid

 class Newtype p u | p - u where
   unpack :: p - u

 instance Newtype p u = Newtype (a - p) (a - u) where
   unpack = (unpack .)

 op :: Newtype p u = (u - p) - p - u
 op _ p = unpack p

 wrap :: Newtype p u = (x - y) -(y - p) - x - u
 wrap pack f = unpack . f . pack

 ala ::  Newtype p' u' = (u - p) -
 ((a - p) - b - p') -
 (a - u) - b - u'
 ala pack hitWith = wrap (pack .) hitWith

...and the suitable Newtype instance for Cont, I
get to write...

  nest = ala Cont traverse id

..separating the newtype encoding from what's really
going on, fusing the map with the sequence, and
generalizing to any old Traversable structure.

Third-order: it's a whole other order.

Conor

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


[Haskell-cafe] Re: Who started 42, and when?

2008-02-01 Thread Martin Lüthi
Hi

Phil Molyneux [EMAIL PROTECTED] writes:
 Hi --- The arbitrary constant was made popular by Douglas Adams in the
 mid-1970s radio series ``A Hitchhikers Guide to the Galaxy'' (a  trilogy in 4
 parts) --- however it does have a basis in the standard  model of physics ---
 a paper in Phys.Rev. of the early 1970s  described the unification of the
 Electro-Weak and Strong nuclear  forces --- the arbitrary constant (of nearly)
 42 appears in the  calculations. I forget the original paper but if you get
 hold of  Frank Close ``The Cosmic Onion'' a graph reproduces the result. I met
 Douglas Adams once at a book signing and asked him how he got hold of  the
 Phys.Rev. paper so early. Technically he should have written that  ``42 is the
 answer to life, the universe and everything except for  gravity and a few
 other arbitrary constants''

In the Japanese culture the number 42 has a very special meaning. I
realized that while discussing cultural differences with a Japanese.
Pronouncing 42 sounds like death or to die. No hotel in Japan has a
room 42. 

After knowing that it is hard to think that Doug Adams was not aware of
that meaning.

Best, Tinu

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


[Haskell-cafe] Issues with hsql-sqllite build; errors from the hackage download

2008-02-01 Thread bbrown
There seems to be an issue with the hsql-sqlite3.  Anyone have a fix.  Should
I use what is from darcs?

Index of /packages/archive/hsql-sqlite3/1.7/logs/failure

The Glorious Glasgow Haskell Compilation System, version 6.8.1

$ runhaskell Setup.lhs configure

Setup.lhs:7:33:
Module
`Distribution.Simple.Utils'
does not export
`rawSystemVerbose'

--
Berlin Brown
[berlin dot brown at gmail dot com]
http://botspiritcompany.com/botlist/?

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


[Haskell-cafe] Re: Who started 42, and when?

2008-02-01 Thread jerzy . karczmarczuk

Martin Lüthi:


In the Japanese culture the number 42 has a very special meaning. I
realized that while discussing cultural differences with a Japanese.
Pronouncing 42 sounds like death or to die. No hotel in Japan has a
room 42.

After knowing that it is hard to think that Doug Adams was not aware of
that meaning.


Phil Molyneux:

... it does have a basis in the standard  model of physics ---
a paper in Phys.Rev. of the early 1970s  described the unification of the
Electro-Weak and Strong nuclear  forces --- the arbitrary constant
(of nearly) 42 appears in the  calculations. I forget the original paper
but if you get hold of  Frank Close ``The Cosmic Onion'' a graph
reproduces the result. I met Douglas Adams once at a book signing and
asked him how he got hold of  the Phys.Rev. paper so early. Technically he
should have written that  ``42 is the answer to life, the universe and
everything except for  gravity and a few other arbitrary constants''



Bother...!

You will discover the third (or the sixth?) moment of the Riemann zeta
function which has this 42 in it, and without doubt, you will find
something in Talmud and the Pyramides. And the mass of the Galaxy which
is 3*10^42.
And it takes light 10^(-42) sec. to cross the diameter of a proton,
although if I were light, I wouldn'd do such silly thing. Fortunately
I am heavy.

And at least one of YOU is 42 years old, and I was once. (Yes, the number
1 which is even more magical).

Perhaps before claiming before you know really something, because Adams
told you so personally, you have a look here.

http://groups.google.com/group/alt.fan.douglas-adams/msg/d1064f7b27808692?dm
ode=sourcehl=en

... And if you run a non-optimized Haskell program which computes the
Fibonacci of 42, then you have to wait so long, that you must build a
special Supercomputer for it. It has, BTW. been built, and it is called
the haskell-cafe mailing list.

Jerzy Karczmarczuk


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


Re: [Haskell-cafe] A handy little consequence of the Cont monad

2008-02-01 Thread Don Stewart
derek.a.elkins:
 On Fri, 2008-02-01 at 16:48 -0500, Dan Licata wrote:
  Not to start a flame war or religious debate, but I don't think that
  eta-expansions should be considered bad style.  I realize that
  composition-style is good for certain types of reasoning, but fully
  eta-expanded code has an important legibility advantage: you can tell
  the shape of its type just by looking at it!  Personally, I'd rather
  read the original version.
 
 Clearly you don't hang out on #haskell enough and have missed the humor.

For those not following, the last thing one does before comitting
any Haskell code, once you've been on #haskell, is to feed it 
to lambdabot for improvement  :)

 dons @pl \f g (a,b) - (f a, g b)
 lambdabot flip flip snd . (ap .) . flip flip fst . ((.) .) . flip . (((.) 
.  (,)) .)

Ah, much better.

We have a strange culture.

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


RE: [Haskell-cafe] Haskell maximum stack depth

2008-02-01 Thread Simon Peyton-Jones
| Yes, using lots of stack is clearly bad with ghc, but this is a ghc
| bug. In fact the only reason these programs do use lots of stack
| (vs. heap) is just a peculiarity of ghc rts implementation, so it
| really should be ghc that fixes the problem, or at least admits
| responsibility :-)

I don't think there's anything fundamental here. GHC allocates the stack in the 
heap, and it can grow as big as you like.  The size limit is simply to catch 
infinite recursion with a more helpful message than heap overflow.  I think.  
There is one peculiarity though: I don't think we ever shrink the stack, so 
once it gets big it stays big.  This could be fixed, though.

In short, feel free to set a very big max-stack size.  If you are going to grow 
a stack of size N or a heap-allocated list of size N, the stack version will 
probably be more efficient -- with the caveat about deallocation that I 
mentioned.

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


Re: [Haskell-cafe] Re: Implementing fixed-sized vectors (using datatype algebra?)

2008-02-01 Thread Isaac Dupree

Wolfgang Jeltsch wrote:

Am Freitag, 1. Februar 2008 05:11 schrieben Sie:

Wolfgang Jeltsch wrote:
Well, the representation (D1,D2,D9) might be considered more readable. 
It has the disadvantage of a fixed maximum size for the numbers.  Which

takes me to a point I had already considered some time ago: Wouldn’t it
be good if we had just a type

data Pair val1 val2 = Pair val1 val2

and if then (val1,val2,…,valn) would just be syntactic sugar for this:

val1 `Pair` (val2 `Pair` (…(valn `Pair` ())…))

I've thought of that too.. besides the asymmetry, the presence of
_|_/seq makes them actually not equivalent though, unfortunately

~Isaac


With Ryan’s proposal (using strictness annotations) the new representation 
should be equivalent to the old one.  Or am I missing something?


adding the strictness annotation seems to make them equivalent, yes I 
agree (I hadn't seen that post when I wrote that reply)


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


[Haskell-cafe] parsec3 pre-release

2008-02-01 Thread Derek Elkins
I'm currently getting Paolo Martini's Google Summer of Code project, an
updated version of Parsec, into a releasable state, and I will be
maintaining it for at least a while.

Paolo's major additions are:
* The Parser monad has been generalized into a Parser monad
  transformer
* The parsers have been generalized to work over a stream of any 
  type, in particular, with bytestrings.

I have made a few minor additions as well:
* There is Haddock documentation for almost all functions
* The Parser monad now has Applicative/Alternative instances

Currently, I am looking for people to give it a go reporting any bugs in
the library or documentation, troubles building it, or changes/features
they would like.  I'm also interested in performance information.

Most old Parsec code should be relatively easy but not trivial to port.
There is a darcs repository on code.haskell.org.  If nothing comes up,
I'll put a package on Hackage in about a week or so.

To get the code:
darcs get http://code.haskell.org/

To build it, the standard cabal commands should work:
http://haskell.org/haskellwiki/Cabal/How_to_install_a_Cabal_package

Alternatively, you can use the cabal-install application:
http://hackage.haskell.org/trac/hackage/wiki/CabalInstall

The documentation can be generated also via the normal cabal routine, or
via cabal-install.


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


[Haskell-cafe] parsec3 pre-release [important note]

2008-02-01 Thread Derek Elkins
I forgot to mention that the Text.Parsec modules should be preferred to
the Text.ParserCombinators.Parsec modules as the Haddock documentation
reveals.

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


[Haskell-cafe] parsec3 pre-release [attempt 2]

2008-02-01 Thread Derek Elkins
[Now with 100% more correct darcs get URLs.]

I'm currently getting Paolo Martini's Google Summer of Code project, an
updated version of Parsec, into a releasable state, and I will be
maintaining it for at least a while.

Paolo's major additions are:
* The Parser monad has been generalized into a Parser monad
  transformer
* The parsers have been generalized to work over a stream of any 
  type, in particular, with bytestrings.

I have made a few minor additions as well:
* There is Haddock documentation for almost all functions
* The Parser monad now has Applicative/Alternative instances

Currently, I am looking for people to give it a go reporting any bugs in
the library or documentation, troubles building it, or changes/features
they would like.  I'm also interested in performance information.

Most old Parsec code should be relatively easy but not trivial to port.
There is a darcs repository on code.haskell.org.  If nothing comes up,
I'll put a package on Hackage in about a week or so.

To get the code:
darcs get http://code.haskell.org/parsec3

To build it, the standard cabal commands should work:
http://haskell.org/haskellwiki/Cabal/How_to_install_a_Cabal_package

Alternatively, you can use the cabal-install application:
http://hackage.haskell.org/trac/hackage/wiki/CabalInstall

The documentation can be generated also via the normal cabal routine, or
via cabal-install.

The Text.Parsec modules should be preferred to the
Text.ParserCombinators.Parsec modules.


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


[Haskell-cafe] newbie q about types

2008-02-01 Thread Logesh Pillay
I have a list.  Each component is a list with 2 whole numbers.  I want 
to multiply the second number by the log of the first

eg
tail ([519432,525806]) * log (head [519432,525806]).

I get the ffg error message:

No instance for (Floating [t])
 arising from a use of `log' at interactive:1:25-50
   Possible fix: add an instance declaration for (Floating [t])
   In the second argument of `(*)', namely
   `log (head [519432, 525806])'
   In the expression:
 tail ([519432, 525806]) * log (head [519432, 525806])
   In the definition of `it':
   it = tail ([519432, 525806]) * log (head [519432, 525806])


I've tried the only type signature I know fromIntegral but it does not 
help.


How to fix?

Thanks
Logesh


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


Re: [Haskell-cafe] newbie q about types

2008-02-01 Thread Jonathan Cast

On 1 Feb 2008, at 10:30 PM, Logesh Pillay wrote:


I have a list.  Each component is a list with 2 whole numbers.


First off, why?  In Haskell (unlike dynamically typed languages like  
Python or Perl), if you know you always have two elements, you want a  
pair (519432,525806), not a list [519432,525806].



  I want to multiply the second number by the log of the first
eg
tail ([519432,525806]) * log (head [519432,525806]).


You mean [519432,525806] !! 1 * log ([519432,525806 !! 0)

or

fst (519432,525806) * log (snd (519432,525806)

or (best of all)

case (519432, 525806) of
  (x, y) - x * log y

or (if you must have a list)

case [519432, 525806] of
  [x, y] - x * log y


I get the ffg error message:

No instance for (Floating [t])


This is because

tail :: [t] - [t]

It doesn't give you a single element; it gives you the whole list!

jcc

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


Re: [Haskell-cafe] newbie q about types

2008-02-01 Thread Luke Palmer
Look at the type of tail:

tail :: [a] - [a]

That is, tail is the list of all elements *except* the head.  You want last.

(Barring style considerations.  Usually in a situation like this you
would use a list of tuples rather than a list of lists, since then you
know at compile time that you have exactly two numbers in each element
of the list).

Luke

On Feb 2, 2008 6:30 AM, Logesh Pillay [EMAIL PROTECTED] wrote:
 I have a list.  Each component is a list with 2 whole numbers.  I want
 to multiply the second number by the log of the first
  eg
 tail ([519432,525806]) * log (head [519432,525806]).

 I get the ffg error message:

  No instance for (Floating [t])
   arising from a use of `log' at interactive:1:25-50
 Possible fix: add an instance declaration for (Floating [t])
 In the second argument of `(*)', namely
 `log (head [519432, 525806])'
 In the expression:
   tail ([519432, 525806]) * log (head [519432, 525806])
 In the definition of `it':
 it = tail ([519432, 525806]) * log (head [519432, 525806])


 I've tried the only type signature I know fromIntegral but it does not
 help.

 How to fix?

 Thanks
 Logesh


 ___
 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[2]: [Haskell-cafe] A handy little consequence of the Cont monad

2008-02-01 Thread Bulat Ziganshin
Hello Conor,

Saturday, February 2, 2008, 1:29:02 AM, you wrote:

nest = ala Cont traverse id

 Third-order: it's a whole other order.

oh! i remember faces of my friends when i showed them something like
sortOn snd . zip [0..]. probably i have the same face now :)))


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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