Re: [Haskell-cafe] implementing python-style dictionary in Haskell

2008-11-19 Thread Don Stewart
dave:
 On Tue, Nov 18, 2008 at 3:52 PM, Don Stewart [EMAIL PROTECTED] wrote:
  dave:
  2008/11/18 kenny lu [EMAIL PROTECTED]:
   The above number shows that my implementations of python style dictionary
   are space/time in-efficient as compared to python.
  
   Can some one point out what's wrong with my implementations?
 
  This isn't really a fair comparison. Map, IntMap, and Trie are
  persistent data structures, and Python dictionaries are ephemeral.
  (That is, when you add a key to a Map, you actually create a new one
  that shares structure with the old one, and both can be used in
  subsequent code. In Python, you would have to copy the dictionary.)
 
 
  Strings, not ByteStrings. that's the difference.
 
 Is that in response to what I wrote, or to the original question?
 
 Speaking of ByteStrings and tries, has anyone implemented a Patricia
 Trie for ByteStrings? I started putting one together a while back, but
 I got distracted and never finished it.

I started putting one together a while back but I got distracted and
never finished it. I think its a couple of days polishing.

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


Re: [Haskell-cafe] GHC 6.10.1 and cabal[-install]

2008-11-19 Thread Duncan Coutts
On Tue, 2008-11-18 at 13:56 -0800, Jason Dagit wrote:

 
 Will Hackage one day provide a way to discover that one
 package has been superceeded by another?
 
 Currently you can see when a newer version of the exact same
 package exists, but (for example) take a took at how many
 gazillion database packages there are up there. Which ones are
 active? Which ones are obsolete? How can I tell??
 
 This has come up before.  As you can see here:
 http://thread.gmane.org/gmane.comp.lang.haskell.cafe/46764
 
 I think we just need someone (how about you!?) to start working on it.

It's even easier than that! Someone has done it already :-)

http://hackage.haskell.org/trac/hackage/ticket/261

Thu Aug 28 16:55:16 CEST 2008  Chry Cheng [EMAIL PROTECTED]
  * Marking packages deprecated
  Fixes ticket no. 261 as discussed in its annotations.  Packages with
deprecated true are excluded from the package list.  Packages with
superseded by tags provide links to their superseding packages in the
package page.

The next bit is in making it easier for maintainers to set this data.

Duncan

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


[Haskell-cafe] UArray Word16 Word32 uses twice as much memory as it should?

2008-11-19 Thread Arne Dehli Halvorsen
Hello,
I am having an issue with these unboxed arrays.
I have some code that creates this structure:: (Array Word16 (UArray Int
Word32), Array Word16 (UArray Int Word8)), and I am finding that it uses
about twice as much memory as I had anticipated.

This tuple is returned strict, and I think I haven't left much room for
other data remaining in memory.

It should hold one Word8 and one Word32 for a data set of 100 million
records, and it uses around 1 gigabyte. By my calculations, it should be
half that.  So I was wondering if I might have hit upon a 64-bit vs 32-bit
issue.

I  compile with:

ghc --make load05 -O1 -funbox-strict-fields -XBangPatterns -fvia-C
(also tried with -O2, and without the -fvia-C)

using the packaged version of ghc 6.10.1 on MacOSX 10.5.5

Grateful for any pointers,

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


Re: [Haskell-cafe] Cabal and more than one version

2008-11-19 Thread Duncan Coutts
On Tue, 2008-11-18 at 16:53 -0800, Jason Dusek wrote:
 In the ticket, someone says:
 
 True though I suspect it looks a bit weird to the
 uninitiated. We know to read the conditional syntax as an
 implication constraint which can be applied in either
 direction but I suspect many people read it in a directed
 functional way.
 
   Does that mean you don't have to actually set 'splitBase'
   explicitly?

No, that is the point. You do not have to. The choice for the flag is
completely determined automatically by the version of the base package
that is chosen.

Because in this construct the flag choice is completely determined by
another choice by the user/environment (the version of a package) then
we do not really need a flag at all. That's why we're considering adding
some syntactic sugar for these kinds of common cases.

But it really would be just syntactic sugar. The semantics are
sufficiently powerful already.

Duncan

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


Re: [Haskell-cafe] Monadic bind with associated types + PHOAS?

2008-11-19 Thread Wouter Swierstra

Hi Ryan,

On 19 Nov 2008, at 04:39, Ryan Ingram wrote:
In HOAS, a lambda expression in the target language is represented  
by a function in the source language:



data ExpE t where
  ApE :: ExpE (a - b) - ExpE a - ExpE b
  LamE :: (ExpE a - ExpE b) - ExpE (a - b)


But without a way to inspect the function inside LamE, you can't get
back to the source code.  You end up adding special constructors for
Primitive or Variable to let you do something with the resultant
structure, which leads to the expression language containing unsafe
constructors which need to be hidden.


There's a perfectly legitimate way to incorporate free variables in  
your expression data type, without sacrificing type safety. You just  
need to parametrise your expression type by the context:


 data Exp g t where
   App :: Exp g (a - b) - Exp g a - Exp g b
   Lam :: (Exp g a - Exp g b) - Exp g (a - b)
   Var :: Var g a - Exp g a

 data Var g a where
   Top :: Var (a,g) a
   Pop :: Var a g - Var a (b, g)

I wouldn't call this unsafe (or at least no more unsafe than HOAS).  
Note that in particular Exp Empty a correspond to closed terms,  
where Empty denotes the empty type.


Secondly, you can always turn a HOAS Exp into non-HOAS expression.  
Essentially, you map applications to applications, etc. The only  
interesting case deal with lambda abstractions - there you need to  
generate a fresh variable name, apply the function to the fresh  
variable, and continue traversing the resulting expression. You might  
be interested in a tutorial Andres Loeh, Conor McBride, and I wrote  
about implementing a dependently typed lambda calculus:


http://www.cs.nott.ac.uk/~wss/Publications/Tutorial.pdf

The quote function in Figure 7 gives the code.


Does anyone think this is a direction worth pursuing?


I'm not convinced yet. The problem is that there's no best way to  
handle binding. HOAS is great for some things (you don't have to write  
substitution), but annoying for others (optimisations or showing  
code). From your message, I couldn't understand why you want to use  
monads/do-notation to handle binding. Care to elaborate?


All the best,

  Wouter



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


Re: [Haskell-cafe] FFI and returning structs

2008-11-19 Thread Donn Cave
Quoth Maurcio [EMAIL PROTECTED]:

| I have not found examples of this in documentation
| or hackage packages: how can I deal with funcions
| returning not pointers to structs but structs
| thenselves?
|
| struct example {...
|
| example function_name (...
|
| My intuition said I could try a data declaration
| that is a properly done instance of Storable, and
| then use that.
|
| data Example = ...
|
| instance Storable Example where ...
|
| But it seems I was wrong.

Eh! probably not wrong - the problem is not how the data looks,
but where it is.

If it were my problem, I would try a wrapper function that
returns the same value as an argument - e.g., if you have
struct X f(), then
  void f_(struct X *x)
  {
  *x = f();
  }

... so your wrapper will look like ccall f_ f :: Ptr X - IO ()
instead of ccall f f :: IO X

Ironically, that's actually just what the original function is doing -
cf. struct return convention, where the caller allocates space
and passes a pointer as a hidden parameter.  But you can't just
declare it that way, because the original f bumps the stack pointer
on return (you may see ret $4 in the assembly code, on Intel hardware)
Try to compile the wrapper with the same compiler that compiled the
original function.

I'm really just guessing that your Haskell compiler doesn't understand
or perfectly handle this particular C wart.  If my suggestion doesn't
work, I may have guessed wrong.

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


Re: [Haskell-cafe] GHC 6.10.1 and cabal[-install]

2008-11-19 Thread Wolfgang Jeltsch
Am Dienstag, 18. November 2008 22:24 schrieben Sie:
   How do I install and configure it so that it is integrated best with
   GHC 6.10.1?  For example, should cabal use some directory in the GHC
   tree to place compiled packages in?

 The defaults for user or global should be fine. There is no need to put
 additional packages into the ghc install tree, indeed I would recommend
 against doing that.

Hmm, /usr/local is not so fine for me since it makes packages hard(er) to 
uninstall.  I use stow (http://www.gnu.org/software/stow/).

  Cabal wants to place package info in $HOME/.cabal.  However, I want to
  install packages globally with sudo.  So I want to have a global package
  cache.  Is there a common directory to be used for that or is
  cabal[-install] only for per-user installations?

 It can do per-user or global. Per-user is the default.

 If you want to do the build as user and just the install as root then
 you can use the --global --root-cmd=sudo options. If you want to use
 this every time then you can set that in the ~/.cabal/config file.

I want the package cache etc. global.  The problem is that with sudo, cabal 
still uses $HOME/.cabal where $HOME is the home directory of the ordinary 
user (not the one of root).

Does --global change the directory for cabal configuration and the package 
cache to something different than $HOME/.cabal?

 The cabal user guide lists the default install directories for global
 and user installs.

Okay, I looked at the cabal-install docs.  And the only doc seems to be the 
output of cabal with the --help option.

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


RE: [Haskell-cafe] Pattern matching on numbers?

2008-11-19 Thread Tobias Bexelius
Yes, fromInteger and == is used for pattern matching on numbers.
However, on GHC you can use -XNoImplicitPrelude to make it use whatever
fromInteger and == that's in scope (without any Num or Eq).

Eg. if == is a method of MyEq class and fromInteger is a method of
MyNum, and MyNum doesn't inherit MyEq, then the type of this function

f 0 = 
f x = 'e' : f (x-1)

Will be inferred as (MyEq a, MyNum a) = a - String

/Tobias

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of David Menendez
Sent: den 19 november 2008 01:00
To: Henning Thielemann
Cc: Haskell Cafe
Subject: Re: [Haskell-cafe] Pattern matching on numbers?

On Tue, Nov 18, 2008 at 6:56 PM, Henning Thielemann
[EMAIL PROTECTED] wrote:

 On Tue, 18 Nov 2008, Ryan Ingram wrote:

 How does this work?

 fac n = case n of
   0 - 1
   _ - n * fac (n-1)

 ghci :t fac
 fac :: (Num t) = t - t

 The first line of fac pattern matches on 0.  So how does this work 
 over any value of the Num typeclass?  I know that the 1 on the rhs 
 of fac are replaced with (fromInteger 1), but what about numeric 
 literals in patterns?  Does it turn into a call to (==)?

 As far as I know, yes. It is even possible to trap into an error on 
 pattern matching this way if fromInteger generates an 'undefined'.

As I understand it, the use of (==) in numeric pattern matching is why
Num requires Eq.

--
Dave Menendez [EMAIL PROTECTED]
http://www.eyrie.org/~zednenem/
___
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] Monadic bind with associated types + PHOAS?

2008-11-19 Thread Ryan Ingram
On Wed, Nov 19, 2008 at 1:04 AM, Wouter Swierstra [EMAIL PROTECTED] wrote:
 I'm not convinced yet. The problem is that there's no best way to handle
 binding. HOAS is great for some things (you don't have to write
 substitution), but annoying for others (optimisations or showing code).

PHOAS solves showing code quite nicely, in my opinion.  I haven't
tried to write a real optimizer using it yet.  It's probably better to
convert to a better intermediate representation and then back when
you're done.

The nice thing about HOAS, in my opinion, is not that it's a good
representation of a language; rather it is that the syntax for
*writing* it in your code is much nicer than the explicit variable
references needed otherwise, because you have lifted part of the
syntax into the host language.

 From your message, I couldn't understand why you want to use 
 monads/do-notation
 to handle binding. Care to elaborate?

Sure; I guess I should explain the motivation a bit.

I really like the syntax for do-notation.  And I really like how great
Haskell is as writing embedded languages, a lot of which comes from
the programmable semicolon that monadic bind gives you.

But there's no equivalent programmable variable bind, or
programmable function application; both are generalizations of
do-notation that would be useful for embedded languages.

So I have been thinking about what makes variable binding special.
What is it that we get from a variable bind? How can we create a
structure that allows one to program  control the results of the
binding values to variables?

This has many uses in embedded languages:
1) We can observe sharing; solving this in DSLs in Haskell usually
leads to really ugly syntax.
2) We can write interpretation functions that can examine all possible
execution paths; this is basically introspection on functions.  This
lets us do whole program optimization or other transformations on the
result of the monadic code.

(2) is usually solved via arrows, although arr makes a true solution
quite difficult.  I don't know of an elegant solution for (1) at all.

Do you have any ideas along these lines?

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


strict collections via types (was: [Haskell-cafe] implementing python-style dictionary in Haskell)

2008-11-19 Thread Claus Reinke
One problem is that Haskell collections are lazy by default.  I'm 
aware of a few use cases where laziness lets you formulate a very

elegant recursive population of a collection, but I think that in
general, strictness is what you want, 


While I strongly agree with the gist of your post, I never liked this 
particular kind of argument - different people have different needs.


and further, that if you want lazy, you store your data as 
one-tuples: data Lazy a = Lazy a  


(If there's a workaround/solution in the other direction, I'd really
like to hear it).


That is the crunch point. If we can't choose between strict and
non-strict usage, the default becomes the only option, and it simply
doesn't fit all use cases. Workarounds are currently somewhat random:

- for indexed collections (which tend to be strict in the keys), one
   can use strict pairs when building from lists of pairs, but that
   doesn't work for all operations (at least not with the current APIs)
- some collections, for a few operations, provide strict alternatives,
   but that doesn't cover much of the API, and isn't even consistent
   over variations of the same kind of collection
- for some types, strict alternatives are provided as separate packages

That means that not only are the usage patterns different, for the
same problem, in different contexts (making switching types harder), 
but one can only get the solutions for some operations in some types:
one is limited to the spartan and incomplete subset of the data type 
API that supports switching between strict and non-strict (check which

operations in Data.Map support both modes, then check what happens
when you want to move from Data.Map to Data.IntMap..). 

Not to mention that the strict alternatives aren't made obvious (you 
have to know that you should look for '-ed variants of operation names 
to get them, sometimes; that goes back all the way to the popular foldl 
with strict accumulator trap) and are documented in names instead of

specified in types.

Using a single set of packages and operations, with standardized
ways of instantiating a collection/type as either strict or non-strict, 
would be much better (well, usable, for a start;-), IMHO.


- using a strict default, optionally disabled via non-strict one-tuples,
   sounds workable (perhaps the one-tuple should be standardized,
   to give the compiler an indication that this is really an annotation,
   and to get similar benefits as from newtype deriving).

- using strictness annotations in types seems simpler, but has the
   drawback that the annotations are really not part of the types;
   types just happen to be a nice place to put annotations that
   amount to invariants ('!t' in some context saying: I always want 
   whnf in this position, not unevaluated thunks) that the compiler

   can use for modifying strictness analysis and code generation.

- an in-between step might be to parameterize collections by a
   type constructor, with two pre-defined constructors (Strict
   and Id) that effectively play the role of annotations while being
   proper parts of types (type constructors), thereby documenting
   intent and enabling (pre-)specialization of code without creating 
   programming or efficiency overheads (at least not for the library

   author - not so sure about library users).

One important point is composition of contexts: if one wants, say,
a Data.Map.Map Key (Data.Map.Map Key type), it should be
possible to specify that one wants both Maps element-strict, and
hence the composed structure strict in type, without obfuscating 
the code with 'seq's or 'Lazy's all over the place. I can see that
working with an annotation + code-generation/specialization 
approach, but how close would a type-tag approach come to 
supporting this?



I'm therefore tempted to suggest that collections should be
strict by default, and in particular, that there should be strict
arrays for arbitrary types, not just the ones that happen to be
unboxable. Unboxing should be an optimization for (some) strict
arrays.


Another suggestion I find myself agreeing with: when I'm looking
for strict variants of standard data types, unboxing is a natural
follow-on optimization, but if unboxing isn't possible, that shouldn't
keep me from getting the benefits of strictness where I need them.

Claus


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


[Haskell-cafe] Re: FFI and returning structs

2008-11-19 Thread Maurí­cio

 I have not  found examples of this in  documentation or hackage
 packages: how  can I deal with funcions  returning not pointers
 to structs but structs thenselves?

 struct example {...

 example function_name (...

 (...)

 (...)

 If  it were  my problem,  I would  try a  wrapper  function that
 returns the same value as an argument - e.g., if you have struct
 X f(), then

   void f_(struct X *x)
   {
   *x = f();
   }

 (...)   Ironically,  that's  actually  just  what  the  original
 function is  doing - cf.  struct return convention,  where the
 caller  allocates  space  and  passes  a  pointer  as  a  hidden
 parameter.  (...)

Can I  be sure  things always goes  like that? I  remember reading
somewhere that if, for instance,  a struct is smaller in size than
a pointer (like a struct made of three chars), the struct could be
returned by itself.

Also, why  Haskell FFI  do not  automate that?  As  long as  it is
Storable data, can't it get the pointer and 'peek' it for me?

Thanks,
Maurício

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


[Haskell-cafe] Re: Can't figure out source of race condition when using System.Process

2008-11-19 Thread Simon Marlow

Rafal Kolanski wrote:


Bryan O'Sullivan wrote:

What is the it that segfaults? The Haskell program shouldn't, at least.


The Haskell program. It does so rarely, however, and I'm unable to 
reproduce it with any consistency, only enough to notice something is 
wrong with what I've written.
Upon closer examination my code also returns an error exit code for 
subprocesses that should've succeeded (pdflatex, but once in a blue moon 
also pstoedit) similarly rarely.


That said, your code for reading from child processes is wrong. You 
should read all of a child's output strictly (i.e. hGetContents alone 
will not do the trick) before you wait for its exit status. Your 
current scheme reverses this order, and there is hence no guarantee 
that it will read anything from the defunct child process. There's 
some possibility that this might be the cause of your segfault, which 
to me would suggest the presence of a bug in the runtime system.


Well, if there's a bug in the runtime system, I'll try to make sure I 
can reproduce it before filing a report.


Even if the bug only happens once every few runs, please report it anyway. 
(I've been chasing a lot of bugs like that recently :-).


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


[Haskell-cafe] Re: Automatic parallelism in Haskell, similar to make -j4?

2008-11-19 Thread Simon Marlow

Bulat Ziganshin wrote:

Hello Chad,

Wednesday, November 5, 2008, 6:34:01 AM, you wrote:


ghc --make -j4 Foo.hs


afair, it was implemented and not shown speed improvements. ask Simon


We did get speed improvements, it was the main case study for the initial 
implementation of shared-memory parallelism in GHC.  See


http://www.haskell.org/~simonmar/bib/multiproc05_abstract.html

However, due to the way GHC is structured internally (it has some global 
caches updated using unsafePerformIO!) the parallel make implementation was 
quite fragile, and wasn't suitable for incorporating into GHC proper.  It's 
certainly possible, but we need to think carefully about how to make these 
caches multi-thread-safe.


Cheers,
Simon

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


Re: [Haskell-cafe] implementing python-style dictionary in Haskell

2008-11-19 Thread Ketil Malde
Tillmann Rendel [EMAIL PROTECTED] writes:

 Why should a Haskell hash table need more memory then a Python hash
 table? I've heard that Data.HashTable is bad, so maybe writing a good
 one could be an option.

One problem is that Haskell collections are lazy by default.  I'm 
aware of a few use cases where laziness lets you formulate a very
elegant recursive population of a collection, but I think that in
general, strictness is what you want, and further, that if you want
lazy, you store your data as one-tuples: data Lazy a = Lazy a  

(If there's a workaround/solution in the other direction, I'd really
like to hear it).

I'm therefore tempted to suggest that collections should be
strict by default, and in particular, that there should be strict
arrays for arbitrary types, not just the ones that happen to be
unboxable. Unboxing should be an optimization for (some) strict
arrays.

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Cabal and more than one version

2008-11-19 Thread Jason Dusek
Duncan Coutts [EMAIL PROTECTED] wrote:
 Jason Dusek wrote:
  In the ticket, someone says:
 
   True though I suspect it looks a bit weird to the
   uninitiated. We know to read the conditional syntax as an
   implication constraint which can be applied in either
   direction but I suspect many people read it in a directed
   functional way.
 
  Does that mean you don't have to actually set 'splitBase'
  explicitly?

 No, that is the point. You do not have to. The choice for the
 flag is completely determined automatically by the version of
 the base package that is chosen.

  When you say chosen is that the same as detected? With
  6.10, both versions of base are available -- what happens
  then? The environment chooses the latest one?

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


[Haskell-cafe] The Monad.Reader - Issue 12: SoC Special

2008-11-19 Thread Wouter Swierstra


I am pleased to announce that a new issue of The Monad.Reader is now  
available:


http://www.haskell.org/haskellwiki/The_Monad.Reader

Issue 12 is another Summer of Code special and consists of the  
following three articles:


* Max Bolingbroke
Compiler Development Made Easy

* Roman Cheplyaka
How to Build a Physics Engine

* Neil Mitchell
Hoogle Overview

The Monad.Reader is a quarterly magazine about functional programming.  
It is less formal than a journal, but more enduring than a wiki page  
or blog post.


If you'd like to write something for the next issue of The  
Monad.Reader, please get in touch. The deadline for the next issue  
will be February 13th.


Looking forward to your submissions,

  Wouter


This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

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


Re: [Haskell-cafe] UArray Word16 Word32 uses twice as much memory as it should?

2008-11-19 Thread Bulat Ziganshin
Hello Arne,

Wednesday, November 19, 2008, 11:57:01 AM, you wrote:

 finding that it uses about twice as much memory as I had anticipated.

it may be
1) GC problem (due to GC haskell programs occupies 2-3x more memory
than actually used)

2) additional data (you not said how long each small array. you should
expect 10-30 additional bytes used for every array)



-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


Re: [Haskell-cafe] streaming translation using monads

2008-11-19 Thread Justin Bailey
On Tue, Nov 18, 2008 at 6:23 PM, Warren Harris [EMAIL PROTECTED] wrote:
 I am working on a query language translator, and although I feel that a
 monadic formulation would work well for this application, I've stumbled on a
 number of questions and difficulties that I thought the knowledgeable people
 here might be able to help me with.


HaskellDB takes a similar approach. It's Query monad allows you to
build queries which are then translated to SQL by a runQuery
function. Could your bind operation collect the 'input' expressions
and then output them all at once via a runTranslation function? Do
you have to do in-place translation?

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


Re: [Haskell-cafe] Re: FFI and returning structs

2008-11-19 Thread Donn Cave
Quoth Maurcio [EMAIL PROTECTED]:

| (...)   Ironically,  that's  actually  just  what  the  original
| function is  doing - cf.  struct return convention,  where the
| caller  allocates  space  and  passes  a  pointer  as  a  hidden
| parameter.  (...)
|
| Can I  be sure  things always goes  like that? I  remember reading
| somewhere that if, for instance,  a struct is smaller in size than
| a pointer (like a struct made of three chars), the struct could be
| returned by itself.

I think you can be reasonably sure it doesn't always work that way!
But if you're interested, you can see what the compiler does with
that smaller struct, looking at the assembly code it generates.
I'm no Intel programmer, but if my test function uses a parameter, I
can see that the parameter is found at an offset, compared to the same
function returning a plain scalar value.  So - yes, the struct value
is returned in a register - but the convention is also observed, with
the hidden parameter.  Using gcc for Intel 80386 family CPU.  Maybe
later I will see how it works on AMD64.

| Also, why  Haskell FFI  do not  automate that?  As  long as  it is
| Storable data, can't it get the pointer and 'peek' it for me?

I can't speak for the FFI authors, and note that I'm not even saying
that it can't do this.  Your inquiry was rather short on details about
what happened, and anyway it's only convenient for me to try it with
NHC, which may not be the compiler you're using.  But if it were up
to me, I doubt that I would support this (struct return), since it's
rare, at best it adds to the difficulty of supporting different hardware
platforms and compilers, and it's easy to work around.

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


Re: [Haskell-cafe] streaming translation using monads

2008-11-19 Thread Warren Harris


On Nov 18, 2008, at 6:53 PM, Brandon S. Allbery KF8NH wrote:


On 2008 Nov 18, at 21:23, Warren Harris wrote:
However, each of the clauses is actually an output routine to send  
the expression that it denotes to a remote server, and a parser for  
receiving the results. Since a clause is really a pair of  
operations, it doesn't seem possible to formulate a monad that will  
compose all the output routines together and compose all the input  
routines together in one shot. (Note that the variables in the  
above code (v1, v2) represent inputs to be received from the remote  
server -- all outputs are packaged into the clause expressions  
themselves and are effectively literals.)



Have you considered using arrows instead?


I'm not that familiar with arrows, but have just looked at some papers  
by Hughes and Paterson. It appears that unlike monads, the right-hand  
side of the arrow operator is not a function, and as such could be  
used to define a pairwise stream sequencing operator for my particular  
case. Are there any specific references that show something like this,  
e.g. for implementing network protocols? (I'm still trying to get my  
head around the basics of arrows.) Thanks,


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


[Haskell-cafe] Re: Begginer question about alignment in Storable

2008-11-19 Thread Mauricio

If you are using hsc2hs (if you are using Cabal this is easy; just
rename the file to *.hsc and Cabal will take care of the rest), then
there is a macro for making this easier and so you don't have to think
about it. (...)


Well, after reading FFI addendum, I'm using
my loyal text editor. Am I supposed to use
something else? Is there something a tool like
hsc2hs or cabal setup can do that is more
portable than what I could write myself? Where
should I learn about that?

Thanks,
Maurício

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


[Haskell-cafe] Re: Monadic bind with associated types + PHOAS?

2008-11-19 Thread Chung-chieh Shan
Ryan Ingram [EMAIL PROTECTED] wrote in article [EMAIL PROTECTED] in 
gmane.comp.lang.haskell.cafe:
 I really like the syntax for do-notation.  And I really like how great
 Haskell is as writing embedded languages, a lot of which comes from
 the programmable semicolon that monadic bind gives you.

AFAICT, standard Haskell 98 already gives you the ability to express
binding and sharing in PHOAS, except not using do-notation:

class Symantics repr where
lam :: (repr a - repr b) - repr (a - b)
app :: repr (a - b) - repr a - repr b
add :: repr Int - repr Int - repr Int
int :: Int - repr Int

let_ :: Symantics repr = repr a - (repr a - repr b) - repr b
let_ e body = app (lam body) e

testSharing :: Symantics repr = repr Int
testSharing = let_ (add (int 3) (int 4)) (\x - add x x)

Oleg has already noted that you can nicely express the showing,
optimization (such as partial evaluation), and transformation (such as
to CPS) of embedded code in this framework.  I agree with him and you
that this representation is a promising direction to explore.

All that's missing in standard Haskell 98, then, is the ability to use
do-notation:

(=) = let_

testSharing = do x - add (int 3) (int 4)
 add x x

But -XNoImplicitPrelude in GHC 6.10 is supposed to enable it, no?

-- 
Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig
2008-11-20 Universal Children's Day  http://unicef.org/
1948-12-10 Universal Declaration of Human Rights http://everyhumanhasrights.org

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


Re: [Haskell-cafe] UArray Word16 Word32 uses twice as much memory as it should?

2008-11-19 Thread Arne Dehli Halvorsen

Bulat Ziganshin wrote:

Hello Arne,

Wednesday, November 19, 2008, 11:57:01 AM, you wrote:

  

finding that it uses about twice as much memory as I had anticipated.



  

Hello, and thank you for your reply.

it may be
1) GC problem (due to GC haskell programs occupies 2-3x more memory
than actually used)
  
I wasn't aware of that - but it should be possible to trigger a GC after 
loading a whole lot of data?

2) additional data (you not said how long each small array. you should
expect 10-30 additional bytes used for every array)
  
The arrays represent the netflix data set: 100 000 000 ratings, given 
for 17770 films.


For each the films, I want to hold (on average, roughly) 2000 ratings, 
held as one person id (32-bit) and one rating (8-bit), in  the respctive 
arrays.


(In addition, I want to be able to load the inversion of this data: for 
all persons, I want to hold their ratings in a similar way:
16-bit film id, 8-bit rating. There are 48 persons, so this should 
be on average 200 entries per person.


I have coded a few approaches to inverting this, but I can't allocate 
the array before traversing the data, because I don't know the sizes.


How can one go about inverting this data in memory?

It seems that any kind of laziness will fill the whole memory before I 
have traversed the whole set - and if I use several accumArrays, it 
seems that it will hold the whole uncompacted dataset in memory between 
accumArrays.


Ideally I want to hold all ratings as well as statistics for all films,  
and the same for all the persons - and then have room to spare for 
running an algorithm...


Best regards,
Arne D Halvorsen

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


Re: [Haskell-cafe] streaming translation using monads

2008-11-19 Thread Warren Harris


On Nov 19, 2008, at 9:11 AM, Justin Bailey wrote:

On Tue, Nov 18, 2008 at 6:23 PM, Warren Harris [EMAIL PROTECTED] 
 wrote:
I am working on a query language translator, and although I feel  
that a
monadic formulation would work well for this application, I've  
stumbled on a
number of questions and difficulties that I thought the  
knowledgeable people

here might be able to help me with.



HaskellDB takes a similar approach. It's Query monad allows you to
build queries which are then translated to SQL by a runQuery
function. Could your bind operation collect the 'input' expressions
and then output them all at once via a runTranslation function?


Thanks for pointing this out. I had looked at Leigen  Meijer's paper  
a while back which describes this, and in one branch of my code taken  
a very similar approach by using an abstract datatype with phantom  
types to represent the target language. However, I had concluded  
(perhaps incorrectly) that the technique was not amenable to streaming  
the results back to the client without first constructing an in-memory  
list with a universal type representing the values returned.


Now perhaps the in-memory list part was a bad conclusion since the  
queries can be decorated with translation functions capable of  
streaming the results out to another channel. However, the use of a  
universal type for the values would still seem to be required since  
there is no way to implement type-indexed values when the queries  
themselves are expressed as an abstract datatype rather than as  
functions. Am I overlooking something?


As an aside, maybe I've been unduly concerned with wrapping the raw  
values in a universal type since I've found that in most cases for my  
target language I must deal with the possibility of null results, and  
must wrap most values in a Maybe type anyway. So I must pay the  
allocation cost in most cases... and with phantom types perhaps I can  
avoid the possibility of dynamic type errors due to unexpected data or  
ill-formed target queries.



Do
you have to do in-place translation?


Not sure I follow.

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


Re: [Haskell-cafe] streaming translation using monads

2008-11-19 Thread Justin Bailey
On Wed, Nov 19, 2008 at 11:50 AM, Warren Harris
[EMAIL PROTECTED] wrote:
 Now perhaps the in-memory list part was a bad conclusion since the queries
 can be decorated with translation functions capable of streaming the results
 out to another channel. However, the use of a universal type for the values
 would still seem to be required since there is no way to implement
 type-indexed values when the queries themselves are expressed as an abstract
 datatype rather than as functions. Am I overlooking something?


If the type of the input determines the type of the output, and the
type of the input can be determined statically, then I think you are
overlooking this technique. But if your application requires that each
input expression be sent to the remote client before type information
can be determined, then you are right.

In the case of HaskellDB, each operator/term in the Query monad
enriches the type information available. Of course, that enrichment
happens at compile time and occurs via type inference. For example,
assuming two tables T1 and T2, with columns T1col and T2col, this
expression:

  simpleQuery = do
 t1 - table T1
 t2 - table T2
 restrict ( .. some expression ...)
 project (t1 ! T1col1 # t2 ! T2col1)

Gives a type similar to Query (RecCons T1Col1 Int (RecCons T2 Col2 Int
RecNil)). RecCons and RecNil are types that allow a list to be built
at the type level. The list carries the column names and types in the
resulting projection. The type information is used  to ensure queries
only refer to columns that exist, datatypes are compared sensibly,
etc. If in your case you can build that kind of structure based purely
on the input language operators/terms, then it seems you could build
the entire output expression in one shot. But again, if input and
output have to be interleaved then I think you are stuck.

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


[Haskell-cafe] Re: streaming translation using monads

2008-11-19 Thread Chung-chieh Shan
Warren Harris [EMAIL PROTECTED] wrote in article [EMAIL PROTECTED] in 
gmane.comp.lang.haskell.cafe:
 However, the use of a  
 universal type for the values would still seem to be required since  
 there is no way to implement type-indexed values when the queries  
 themselves are expressed as an abstract datatype rather than as  
 functions. Am I overlooking something?

You might find inspiration in the fact that printf and scanf can be
expressed in ML/Haskell without any fancy type-system features.

http://www.brics.dk/RS/98/12/
http://cs.nyu.edu/zheyang/papers/YangZ--ICFP98.html
http://article.gmane.org/gmane.comp.lang.haskell.general/16409
http://www.itu.dk/people/mir/typesafepatterns.pdf

Credits to: Olivier Danvy, Zhe Yang, Kenichi Asai, Oleg Kiselyov,
Morten Rhiger.

-- 
Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig
2008-11-20 Universal Children's Day  http://unicef.org/
1948-12-10 Universal Declaration of Human Rights http://everyhumanhasrights.org

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


[Haskell-cafe] Deprecated packages

2008-11-19 Thread Andrew Coppin

Jason Dagit wrote:



On Tue, Nov 18, 2008 at 2:03 PM, Jason Dagit [EMAIL PROTECTED] 
mailto:[EMAIL PROTECTED] wrote:




On Tue, Nov 18, 2008 at 2:00 PM, Andrew Coppin
[EMAIL PROTECTED] mailto:[EMAIL PROTECTED]
wrote:

Jason Dagit wrote:


   Will Hackage one day provide a way to discover that one
package
   has been superceeded by another?

   Currently you can see when a newer version of the exact
same
   package exists, but (for example) take a took at how many
   gazillion database packages there are up there. Which
ones are
   active? Which ones are obsolete? How can I tell??


This has come up before.  As you can see here:
http://thread.gmane.org/gmane.comp.lang.haskell.cafe/46764

I think we just need someone (how about you!?) to start
working on it.


What do I need to do? Just obtain the Hackage source code and
submit a Darcs patch or something? Or is it harder than that?


A darcs patch should work.  If you look in the thread I linked to
you'll see this message by Thomas M. DuBuisson:


By copy and paste, my apologies:
http://article.gmane.org/gmane.comp.lang.haskell.cafe/46773


Hackage ticket #261 appears to contain the required patch already.

http://hackage.haskell.org/trac/hackage/ticket/261

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


Re: [Haskell-cafe] GHC 6.10.1 and cabal[-install]

2008-11-19 Thread Daniel McAllansmith
On Wed, 19 Nov 2008 21:27:36 Duncan Coutts wrote:
 It's even easier than that! Someone has done it already :-)

 http://hackage.haskell.org/trac/hackage/ticket/261

 Thu Aug 28 16:55:16 CEST 2008  Chry Cheng [EMAIL PROTECTED]
   * Marking packages deprecated
   Fixes ticket no. 261 as discussed in its annotations.  Packages with
 deprecated true are excluded from the package list.  Packages with
 superseded by tags provide links to their superseding packages in the
 package page.

Does excluded from the package list mean that deprecated packages won't show 
up on http://hackage.haskell.org/packages/archive/pkg-list.html ?

If so, how does one go about finding and downloading deprecated packages?  
Rely on the search function to find the package page?
How do you get a comprehensive list of the deprecated packages that have 
existed?

Perhaps there should be a deprecated-pkg-list.html page.
If being superseded implies deprecation this page is also where the superseded 
packages would go, with appropriate supersedes/superseded-by links between 
them.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: Fwd: [Haskell-cafe] implementing python-style dictionary in Haskell

2008-11-19 Thread Duncan Coutts
On Tue, 2008-11-18 at 22:42 +0100, Alberto G. Corona wrote:
 sorry, Dons,
 
 -- Forwarded message --
 From: Alberto G. Corona [EMAIL PROTECTED]
 Date: 2008/11/18
 Subject: Re: [Haskell-cafe] implementing python-style dictionary in
 Haskell
 To: Don Stewart [EMAIL PROTECTED]
 
 
 By the way byteStrings are wonderful, but, it  isn´t true that
 byteStrings are not so fast for managing short strings, for example
 keys ?

For short strings they're fast to use but not fast to construct and not
very memory efficient. There's 20 bytes overhead per ByteString. A
packed string type optimised for short strings would make different
design decisions.

Duncan


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


Re: [Haskell-cafe] streaming translation using monads

2008-11-19 Thread Warren Harris


On Nov 19, 2008, at 12:19 PM, Justin Bailey wrote:


On Wed, Nov 19, 2008 at 11:50 AM, Warren Harris
[EMAIL PROTECTED] wrote:
Now perhaps the in-memory list part was a bad conclusion since the  
queries
can be decorated with translation functions capable of streaming  
the results
out to another channel. However, the use of a universal type for  
the values

would still seem to be required since there is no way to implement
type-indexed values when the queries themselves are expressed as an  
abstract

datatype rather than as functions. Am I overlooking something?



If the type of the input determines the type of the output, and the
type of the input can be determined statically, then I think you are
overlooking this technique. But if your application requires that each
input expression be sent to the remote client before type information
can be determined, then you are right.

In the case of HaskellDB, each operator/term in the Query monad
enriches the type information available. Of course, that enrichment
happens at compile time and occurs via type inference. For example,
assuming two tables T1 and T2, with columns T1col and T2col, this
expression:

 simpleQuery = do
t1 - table T1
t2 - table T2
restrict ( .. some expression ...)
project (t1 ! T1col1 # t2 ! T2col1)

Gives a type similar to Query (RecCons T1Col1 Int (RecCons T2 Col2 Int
RecNil)). RecCons and RecNil are types that allow a list to be built
at the type level. The list carries the column names and types in the
resulting projection. The type information is used  to ensure queries
only refer to columns that exist, datatypes are compared sensibly,
etc. If in your case you can build that kind of structure based purely
on the input language operators/terms, then it seems you could build
the entire output expression in one shot. But again, if input and
output have to be interleaved then I think you are stuck.


What you describe is very similar to my current implementation, except  
I'm using a continuation function to receive the results input from  
the remote server rather than creating a list. The continuation's type  
(a curried function) is analogous to a list at the type level, if I  
understand correctly. However, since what I would like to do is stream  
the results in from one server and out to another (translating as I  
go), I really need some way to hook my translation in between each  
primitive field read from the input. So inside the body of the  
'project' call you've given above, I might like to say something like:


  v1 - t1 ! T1col1;
  v2 - t2 ! T2col1;
  send client (trans v1 v2);
  return ()

However, since this input-receiving expression is now expressed as  
monad, it doesn't seem possible to use it to simultaneously formulate  
the output expressions that must be sent to the remote server to cause  
T1col1 and T2col1 to be requested.


In my particular application, the remote server not only handles  
simple directives to retrieve sequences of primitives like T1col1,  
T2col1, but also higher-order formulations of them as lists and  
tuples. So the server may be sent a request like (T1col1, (list  
(T2col1, T2col2))) meaning request the tuple of T1col1 followed by a  
(possibly long) sequence of T2col1, T2col2 pairs and I want to be  
able to translate the incoming result stream without holding the  
entire thing in memory.


Obviously I can do this by having one operation to generate the  
outbound query from a target language expression (implemented with an  
algebraic datatype), and another operation to handle the results based  
on the same expression, but it seems like some sort of formulation  
should be possible that allows both operations to be expressed  
simultaneously. In fact, I get that with the continuation-oriented  
combinators I mentioned earlier, but in practice I've found them to be  
very hard to work with. Just to make it more concrete, the above  
example might be expressed with my continuation-based combinators as:


T1col1 == (\ k t1 - send client (trans1 t1); k) ++
list (T2col1 ++ T2col2
   == (\ k t2c1 t2c2 - send client (trans2 t2c1 t2c2); k))) + 
+ ...


Here, the first function receives the value read from T1col1,  
translates it and send it to the originator of the request. This  
function is substituted for the an overall continuation -- receives  
the overall continuation as its first argument, k, and returns it at  
the end without passing any values to it. This effectively consumes  
the value t1. The second function is similar, and is called for each  
pair received from the list. The combinator '++', primitive directives  
like T1col1, and higher-order directives like 'list' are responsible  
for dealing with the overall expression grammar (i/o of delimiters,  
etc) and folding the overall continuation through the results as they  
are received.


Sorry for being so long-winded here... I really appreciate your input.

Warren

Re: [Haskell-cafe] portable arrow instances

2008-11-19 Thread Conal Elliott
Hi Wolfgang,

I use CPP to manage such differences between 6.8, 6.9, and 6.10.  As an
example, see
http://hackage.haskell.org/packages/archive/TypeCompose/latest/doc/html/src/Control-Compose.html.

Regards, - Conal

On Tue, Nov 18, 2008 at 6:01 AM, Wolfgang Jeltsch 
[EMAIL PROTECTED] wrote:

 Hello,

 how do I make a library work with both GHC 6.8 and GHC 6.10?  According to
 http://www.haskell.org/haskellwiki/Upgrading_packages#Arrow_instances, I
 should change all my Arrow instances but then they don't work with GHC 6.8
 anymore, do they?  Or is the solution to force GHC 6.8 users to use
 base-4.0.0.0?

 Best wishes,
 Wolfgang
 ___
 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] Hackage policy question

2008-11-19 Thread John Meacham
The usual solution to this is the 'release version', which is used in
most (all?) other packaging systems. namely, you have foo-1.2-4, where 4 is the
release version which documents what version the meta-info is. For
instance, when bugs are fixed in the rpm spec file or deb package that
number is bumped and it is independent of the underlying packaged
softwares release. It would be very useful if hackage could support
something like this.

John
 
-- 
John Meacham - ⑆repetae.net⑆john⑈
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe