Re: [Haskell-cafe] Linker problems linking FFI import call in Windows

2008-07-15 Thread Olivier Boudry
On Tue, Jul 15, 2008 at 11:51 PM, PJ Durai <[EMAIL PROTECTED]> wrote:
> I am trying to import some functions from a windows DLL. I am getting
> strange errors. (This used to work with previous versions of GHC.  6.6
> I think.).

You may have to create an import library for the DLL. I had a similar
problem and solved it that way.

Look at http://www.emmestech.com/moron_guides/moron1.html for advices
on how to create such a library.

My problem was that the exports in the dll were prefixed with an
underscore. I had to remove them from the .def file before creating
the import library.

Best regards,

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


[Haskell-cafe] Euler 201 performance mystery

2008-07-15 Thread nadine . and . henry

Dear Group,

I've spend the last few days figuring out the solution to Euler Problem 201 in
haskell.  I first tried a relatively elegant approach based on Data.Map but
the performance was horrible.  I never actually arrived at the answer.  I then
rewrote the same algorithm using STUArrays and it was lightning.  I have
posted both versions of the code at:
http://www.maztravel.com/haskell/euler_problem_201.html
and would appreciate any insights that you master haskellers can provide on
why the speed difference is so huge.  Thanks in advance.
Henry Laxen

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


Re: [Haskell-cafe] Getting latest GHC-head/libraries takes forever

2008-07-15 Thread Duncan Coutts

On Tue, 2008-07-15 at 19:45 -0500, Austin Seipp wrote:
> For the purpose of experimenting with NDP I went through the
> process of getting the GHC head from darcs.haskell.org. As 
> specified in the developer wiki[1], using darcs get is basically
> not possible because there're so many patches. So I downloaded
> 
> http://darcs.haskell.org/ghc-HEAD-2008-06-06-ghc-corelibs-testsuite.tar.bz2
> 
> This alone took over *7 hours* using wget because it could never get
> a connection faster than 5kb/s.

darcs.haskell.org is still being throttled. The server move means the
machine itself has more bandwidth but the apache http server is still
configured to limit connection speed. I believe this is supposed to
change at some point but I don't know when.

I've no idea about what's going on with darcs though. I know there are
some issues with case-insensitive file systems or as you speculate it
might be a darcs 1 vs 2 issue. Ask a darcs expert.

Duncan

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


Re: [Haskell-cafe] Getting latest GHC-head/libraries takes forever

2008-07-15 Thread Brandon S. Allbery KF8NH


On 2008 Jul 15, at 20:45, Austin Seipp wrote:


For the purpose of experimenting with NDP I went through the
process of getting the GHC head from darcs.haskell.org. As
specified in the developer wiki[1], using darcs get is basically
not possible because there're so many patches. So I downloaded

http://darcs.haskell.org/ghc-HEAD-2008-06-06-ghc-corelibs-testsuite.tar.bz2

This alone took over *7 hours* using wget because it could never get
a connection faster than 5kb/s.


FWIW I did manage to get it using darcs (!) having not checked the  
wiki to see that it was supposedly impossible these days.  (Well, I  
did get --partial.  --all is a definite mistake.)


I let darcs sit for over another hour and a half trying to pull  
patches

from darcs.haskell.org for the libraries and the testsuite.

It never got past packages/base. In fact, it never even got to  
*getting* the
patches from the base repository, it sat there, stuck at the  
'identifying repository'
stage (darcs 2.0.2) for over an hour, making my processor go round  
and round at
99% CPU usage the entire way, never accomplishing anything. What  
makes it even stranger
is that it got the latest patches for the testsuite and the array  
package pretty quick.
It just got permanently stuck on base for some reason and never went  
further.


Mine stopped at array.  That said, it does seem really slow; given  
your comment about downloading, this sounds like a problem with  
darcs.haskell.org in general.  But it might be worth grabbing darcs1  
for Leopard and trying again.


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
electrical and computer engineering, carnegie mellon universityKF8NH


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


[Haskell-cafe] Getting latest GHC-head/libraries takes forever

2008-07-15 Thread Austin Seipp
For the purpose of experimenting with NDP I went through the
process of getting the GHC head from darcs.haskell.org. As 
specified in the developer wiki[1], using darcs get is basically
not possible because there're so many patches. So I downloaded

http://darcs.haskell.org/ghc-HEAD-2008-06-06-ghc-corelibs-testsuite.tar.bz2

This alone took over *7 hours* using wget because it could never get
a connection faster than 5kb/s.

After downloading I changed to the directory and ran 'darcs pull -a'.
Nothing bad happened here, darcs pulled most of the changes pretty quick
so I had an up to date GHC.

However, when trying to use the ./darcs-all script to pull in the
latest library/testsuite changes, things go horribly, horribly wrong. 

I let darcs sit for over another hour and a half trying to pull patches
from darcs.haskell.org for the libraries and the testsuite.

It never got past packages/base. In fact, it never even got to *getting* the
patches from the base repository, it sat there, stuck at the 'identifying 
repository'
stage (darcs 2.0.2) for over an hour, making my processor go round and round at
99% CPU usage the entire way, never accomplishing anything. What makes it even 
stranger
is that it got the latest patches for the testsuite and the array package 
pretty quick.
It just got permanently stuck on base for some reason and never went further.

Also, I tried pulling package-ndp a few days ago while using an older 
development snapshot
of GHC (not the darcs repository, a nightly HEAD tarball of ghc.)
Just pulling 500 patches from http://darcs.haskell.org/packages/ndp took over
an hour, but at least it got done. It didn't build properly so I thought I'd
get the latest darcs version of GHC instead, and here I am.

Has anybody experienced anything like this recently? Off the top of my head the 
only
things that possibly come to mind are:

1) darcs.haskell.org is just really slow or under -constant- heavy load.
2) the darcs repositories are in darcs-1 format, so darcs-2 is having issues 
when
 trying to pull the patches.
3) Diabolical connection-killing ninjas.

None of these 3 possibilities are really 'great,' and none of them help me get 
the
latest version of GHC, the libs, and NDP any faster then a narcoleptic snail.

If instead this is a techincal issue with, say, darcs that someone is aware of, 
I'm
using OS X Leopard, 10.5.4 with a statically linked darcs-2.0.2 binary from [2].

[1] http://hackage.haskell.org/trac/ghc/wiki/Building/GettingTheSources
[2] 
http://wiki.darcs.net/DarcsWiki/CategoryBinaries#head-25c8108e9d719be30a8cc6bcc86ce243a78b8c25
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Mutually recursive modules and google protocol-buffers

2008-07-15 Thread Jason Dusek
John Meacham <[EMAIL PROTECTED]> wrote:
> Chris Kuklewicz wrote:
> > I have reached an impasse in designing a Haskell API for the
> > google's The messages in protobuf are defined in a namespace
> > that nests in the usual hierarchical OO style that Java
> > encourages.
>
> > To avoid namespace conflicts, I made a hierarchy of modules.
>
> I wonder if this is the root of your issue, OO concepts don't
> map directly to haskell concepts a lot of the time. You may
> end up with some very atypical haskell code if you try to copy
> OO designs directly.

  What do you think is a good approach to a protocol buffer
  parser generator?

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


Re: [Haskell-cafe] Can't get Haddock 2.0 anchor reference to work

2008-07-15 Thread Gwern Branwen
On 2008.07.15 13:59:32 -0700, Mike Gunter <[EMAIL PROTECTED]> scribbled 0.2K 
characters:
>
> How are anchor references in Haddock supposed to work?
>
> When I use "Dir.Mod#foo", the resulting HTML contains:
>
> instead of the more desirable:
>
>
> User error or bug?
>
> thanks,
> -m

For what it's worth, I've run into this issue with XMonad docs before.

For example: 

 has a line "See XMonad.Doc.Extending#Editing_key_bindings for instructions on 
how to edit your key bindings."; the source is "See 
"XMonad.Doc.Extending#Editing_key_bindings" for instructions on how to
edit your key bindings."

This links to 
.
 The source

At least in Firefox, clicking only reloads the current page, and doesn't go 
down the several sections to the key binding information. (When I tried with my 
offline docs, it didn't even reload, just errored.)

--
gwern
Bess fritz Team espionage Blowfish Kosovo SIG LF ISPE Saudi


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


[Haskell-cafe] Linker problems linking FFI import call in Windows

2008-07-15 Thread PJ Durai
Greetings

I am trying to import some functions from a windows DLL. I am getting
strange errors. (This used to work with previous versions of GHC.  6.6
I think.).

This is my import statement:

foreign import stdcall  "ace.h AdsConnect" adsConnect' :: CString ->
Ptr CInt -> IO CInt

This is the build output.

C:\moonar>\bin\make.exe
ghc --make -ffi main.hs  -ffi adsapi.hs -optc -DWIN32 native.cpp  -lace32 -L/hom
e/pjdurai/dev/moonar  -L/tmp/Advantage -o moonar.exe
[1 of 2] Compiling AdsApi   ( adsapi.hs, adsapi.o )
[2 of 2] Compiling Main ( main.hs, main.o )
Linking moonar.exe ...

adsapi.o(.text+0x124):fake: undefined reference to [EMAIL PROTECTED]'
adsapi.o(.text+0x260):fake: undefined reference to [EMAIL PROTECTED]'
collect2: ld returned 1 exit status
make: *** [main.exe] Error 1

It actually links without errors if I use 'ccall' instead of
'stdcall'. But the executable segfaults when the function is called.

I had the same code working with 'stdcall' declaration a while ago.
(With GCH 6.6 I think)

I am using ghc-6.8.3 on Windows XP SP2.

appreciate your time.
thanks
pj
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Mutually recursive modules and google protocol-buffers

2008-07-15 Thread John Meacham
On Tue, Jul 15, 2008 at 12:21:16PM +0100, Chris Kuklewicz wrote:
> I have reached an impasse in designing a Haskell API for the google's
> The messages in protobuf are defined in a namespace that nests in the usual
> hierarchical OO style that Java encourages.
>
> To avoid namespace conflicts, I made a hierarchy of modules.

I wonder if this is the root of your issue, OO concepts don't map
directly to haskell concepts a lot of the time. You may end up with some
very atypical haskell code if you try to copy OO designs directly. 

John 

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


[Haskell-cafe] Can't get Haddock 2.0 anchor reference to work

2008-07-15 Thread Mike Gunter

How are anchor references in Haddock supposed to work?

When I use "Dir.Mod#foo", the resulting HTML contains:
   
instead of the more desirable:
   

User error or bug?

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


Re: [Haskell-cafe] CAL (OpenQuark) and enterprise

2008-07-15 Thread Daniil Elovkov

fero wrote:

And what if writing new application? Has anybody experience with enterprise
application in functional language? Is it really clearer? I can see a
advantage in using Scala but it doesn't have some features from Haskell or
CAL or requires more code to write. Or better has anybody experience with
the same and functional language for JVM? And what about ORM (e.g.
Hibernate)? And what about objects, they are stateful itself. And CRUD is a
very common part of enterprise applications and I think it's easier in
imperative style (client is declarative of course but it assigns values to
fields). I am interested in ours opinions/experience in business logic (not
any infrastructure or client stuff) for apps such as
accounting/bank/insurance/document management... systems in functional
languages. Sometimes the rules for these kind of apps is more complex that
it seem to be and such systems are maintained for many years (some even
decades) so it needs to be readable. Rule engines are very popularized among
java community now but I think many logic can be expressed clearer in
functions. It is maybe useful for some kind of logic (e.g. calculate price
with discounts) but for what I do I can write the same clearer in java that
in rule engine (and much clearer in Haskell and I am only beginner. What
will come after few years coding;). 



You may start writing more obscure code.

Look at this:
http://www.willamette.edu/~fruehr/haskell/evolution.html

This is humour, of course.



Miles Sabin wrote:

On Wed, Jul 9, 2008 at 6:28 PM, Neil Mitchell <[EMAIL PROTECTED]>
wrote:

On the Haskell list I think its fair to say everyone recommends you
should use Haskell.

Not necessarily. If the OP has a significant body of existing Java
code (s)he has to work with (which is what the question suggests) then
Scala would most likely be a very good place to look.



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


Re: [Haskell-cafe] CAL (OpenQuark) and enterprise

2008-07-15 Thread fero

And what if writing new application? Has anybody experience with enterprise
application in functional language? Is it really clearer? I can see a
advantage in using Scala but it doesn't have some features from Haskell or
CAL or requires more code to write. Or better has anybody experience with
the same and functional language for JVM? And what about ORM (e.g.
Hibernate)? And what about objects, they are stateful itself. And CRUD is a
very common part of enterprise applications and I think it's easier in
imperative style (client is declarative of course but it assigns values to
fields). I am interested in ours opinions/experience in business logic (not
any infrastructure or client stuff) for apps such as
accounting/bank/insurance/document management... systems in functional
languages. Sometimes the rules for these kind of apps is more complex that
it seem to be and such systems are maintained for many years (some even
decades) so it needs to be readable. Rule engines are very popularized among
java community now but I think many logic can be expressed clearer in
functions. It is maybe useful for some kind of logic (e.g. calculate price
with discounts) but for what I do I can write the same clearer in java that
in rule engine (and much clearer in Haskell and I am only beginner. What
will come after few years coding;). 



Miles Sabin wrote:
> 
> On Wed, Jul 9, 2008 at 6:28 PM, Neil Mitchell <[EMAIL PROTECTED]>
> wrote:
>> On the Haskell list I think its fair to say everyone recommends you
>> should use Haskell.
> 
> Not necessarily. If the OP has a significant body of existing Java
> code (s)he has to work with (which is what the question suggests) then
> Scala would most likely be a very good place to look.
> 
> Cheers,
> 
> 
> Miles
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 

-- 
View this message in context: 
http://www.nabble.com/CAL-%28OpenQuark%29-and-enterprise-tp18366397p18474222.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: [Haskell-cafe] Remote control of firefox through Haskell?

2008-07-15 Thread Jefferson Heard
Thanks, Rahul, Don.  These work...
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Remote control of firefox through Haskell?

2008-07-15 Thread Don Stewart
jefferson.r.heard:
> Is there a library out there that will allow me to remote-control the
> firefox or mozilla browsers, e.g. change the current page, open a new
> tab?

Yeah, use the haskell selenium bindings, on hackage.haskell.org

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


Re: [Haskell-cafe] Remote control of firefox through Haskell?

2008-07-15 Thread Rahul Kapoor
Selenium (http://selenium.openqa.org/) might do what you want.
The bindings were announced on this list a little while ago
(http://tinyurl.com/se-bindings)

On Tue, Jul 15, 2008 at 3:12 PM, Jefferson Heard
<[EMAIL PROTECTED]> wrote:
> Is there a library out there that will allow me to remote-control the
> firefox or mozilla browsers, e.g. change the current page, open a new
> tab?
>
> --
> I try to take things like a crow; war and chaos don't always ruin a
> picnic, they just mean you have to be careful what you swallow.
>
> -- Jessica Edwards
> ___
> 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] Remote control of firefox through Haskell?

2008-07-15 Thread Jefferson Heard
Is there a library out there that will allow me to remote-control the
firefox or mozilla browsers, e.g. change the current page, open a new
tab?

-- 
I try to take things like a crow; war and chaos don't always ruin a
picnic, they just mean you have to be careful what you swallow.

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


Re: [Haskell-cafe] Mutually recursive modules and google protocol-buffers

2008-07-15 Thread Stuart Cook
On Wed, Jul 16, 2008 at 12:54 AM, Henning Thielemann
<[EMAIL PROTECTED]> wrote:
> Sooner or later you want generalize your datatypes. Then you can define
>   data A b = A b
>  and you do not need to import B any longer. I do not know if this is a
> generally applicable approach, but it helped me in some cases.

This only really works if it's "natural" for A to be polymorphic in b.
Otherwise you end up with all sorts of irrelevant administrative type
parameters polluting your signatures.

(I recently had a similar problem with mutually recursive modules; I
ended up deciding to write my program in not-Haskell instead, which
made me a little sad.)


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


Re: [Haskell-cafe] Mutually recursive modules and google protocol-buffers

2008-07-15 Thread Sterling Clover
What about generating the verbose accessor/single module code, and  
then creating a hierarchical module space as well, all importing your  
Base module, and reexporting the data types you want as well as less  
verbosely named accessor functions? Of course, this will break record  
update syntax, but maybe you could move to functional references  
instead -- given that you're generating all the code to begin with,  
autogenerating fref/lens style getter-setter pairs shouldn't be any  
more work.


--Sterl

On Jul 15, 2008, at 10:43 AM, Chris Kuklewicz wrote:

Ah, a teachable moment.  One of us is not entirely correct about  
what GHC can do with this example.  Hopefully I am wrong, but my  
experiments...


Max Bolingbroke wrote:

And there is no way ghc can compile these in separate modules.

I may be being redundant here, but you may not know that GHC actually
can compile mutually recursive modules. See
http://www.haskell.org/ghc/docs/latest/html/users_guide/separate- 
compilation.html#mutual-recursion

. Of course, this is not a great solution either, as creating hs-boot
files is a bit tedious, but at least the option is there.
Cheers,
Max


Consider these 3 files:

A.hs:

module A(A) where
import B(B)
data A = A B


B.hs

module B(B) where
import A(A)
data B = B A


Main.hs
> module Main where
> import A
> import B
> main = return ()

There is no way to create a "A.hs-boot" file that has all of
  (1) Allows A.hs-boot to be compiled without compiling B.hs first
  (2) Allows B.hs (with a {-# SOURCE #-} pragma) to be compiled  
after A.hs-boot
  (3) Allows A.hs to compiled after A.hs-boot with a consistent  
interface


But this "Main2.hs" file works fine:

module Main where
data A = A B
data B = B A
main = return ()


But in "Main2.hs" I cannot define two record field accessors such as
> data A = A { getName :: B}
> data B = B { getName :: A}
because there cannot be two different "getName" created in the same  
namespace.


There is no way GHC can put the two field accessors in different  
module namespaces because their "data" types include mutual recursion.


So I can choose one of
  (*) Ignore mutual recursion and make all such .proto  
specifications break
  (*) Autogenerate very verbose data type names and put them all in  
the same module to allow mutual recursion. And then either

  (**) Autogenerate even more verbose field accessor names
  (**) Define no field accessors and create some poor  
replacement, such as



class Field'Name a b | a ->b where
  getName :: a -> b
  setName :: a -> b -> a




Cheers,
  Chris
___
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] Mutually recursive modules and google protocol-buffers

2008-07-15 Thread Roberto Zunino

Chris Kuklewicz wrote:

There is no way to create a "A.hs-boot" file that has all of
  (1) Allows A.hs-boot to be compiled without compiling B.hs first
  (2) Allows B.hs (with a {-# SOURCE #-} pragma) to be compiled after 
A.hs-boot

  (3) Allows A.hs to compiled after A.hs-boot with a consistent interface


I thought the following A.hs-boot would suffice:

module A(A) where
data A

There's no need to provide the data constructors for type A. Does this 
violate any of the goals above?


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


Re: [Haskell-cafe] Mutually recursive modules and google protocol-buffers

2008-07-15 Thread Henning Thielemann


On Tue, 15 Jul 2008, Chris Kuklewicz wrote:


Consider these 3 files:

A.hs:

module A(A) where
import B(B)
data A = A B


B.hs

module B(B) where
import A(A)
data B = B A


Main.hs

module Main where
import A
import B
main = return ()



Sooner or later you want generalize your datatypes. Then you can define
   data A b = A b
  and you do not need to import B any longer. I do not know if this is a 
generally applicable approach, but it helped me in some cases.
 There is still a problem with mutually recursive classes. In the one case 
where I had this problem, I could solve it the opposite way, namely by 
turning one type variable into a concrete type, which could represent all 
values one could represent with the variable type.

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


[Haskell-cafe] Re: ANN: haskell-src-exts 0.3.5

2008-07-15 Thread ChrisK

Thanks for the fix.  I have gotten the darcs version and I am compiling...

Niklas Broberg wrote:

Hi all,

I'm pleased to report that haskell-src-exts is now updated to
understand Template Haskell syntax (it used to understand pre-6.4 TH,
but now it works with the current version). At least I hope so, I
didn't have much TH code to try it on so if you find some bugs just
let me know. It wasn't all that hard to fix though, so I'm pretty
confident it actually works.

Get the code:
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/haskell-src-exts-0.3.5
darcs get http://code.haskell.org/HSP/haskell-src-exts

Cheers,

/Niklas


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


Re: [Haskell-cafe] Mutually recursive modules and google protocol-buffers

2008-07-15 Thread Chris Kuklewicz
Ah, a teachable moment.  One of us is not entirely correct about what GHC can do 
with this example.  Hopefully I am wrong, but my experiments...


Max Bolingbroke wrote:

And there is no way ghc can compile these in separate modules.


I may be being redundant here, but you may not know that GHC actually
can compile mutually recursive modules. See
http://www.haskell.org/ghc/docs/latest/html/users_guide/separate-compilation.html#mutual-recursion
. Of course, this is not a great solution either, as creating hs-boot
files is a bit tedious, but at least the option is there.

Cheers,
Max


Consider these 3 files:

A.hs:

module A(A) where
import B(B)
data A = A B


B.hs

module B(B) where
import A(A)
data B = B A


Main.hs
> module Main where
> import A
> import B
> main = return ()

There is no way to create a "A.hs-boot" file that has all of
  (1) Allows A.hs-boot to be compiled without compiling B.hs first
  (2) Allows B.hs (with a {-# SOURCE #-} pragma) to be compiled after A.hs-boot
  (3) Allows A.hs to compiled after A.hs-boot with a consistent interface

But this "Main2.hs" file works fine:

module Main where
data A = A B
data B = B A
main = return ()


But in "Main2.hs" I cannot define two record field accessors such as
> data A = A { getName :: B}
> data B = B { getName :: A}
because there cannot be two different "getName" created in the same namespace.

There is no way GHC can put the two field accessors in different module 
namespaces because their "data" types include mutual recursion.


So I can choose one of
  (*) Ignore mutual recursion and make all such .proto specifications break
  (*) Autogenerate very verbose data type names and put them all in the same 
module to allow mutual recursion. And then either

  (**) Autogenerate even more verbose field accessor names
  (**) Define no field accessors and create some poor replacement, such as


class Field'Name a b | a ->b where
  getName :: a -> b
  setName :: a -> b -> a




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


Re: [Haskell-cafe] Type level sets with GADTs, fundeps etc

2008-07-15 Thread Jeff Polakow
Hello,

> data LSet t where
> Nil :: LSet Nil
> Ins :: (Member a t b
>   , If b t (a ::: t) r) 
>   => L a -> LSet t -> LSet r
> 
Try replacing both original occurrences of r, i.e. (untested)

Ins :: (Member a t b, If b t (a ::: t) (LSet r)) => L a -> LSet t -> 
LSet r

-Jeff



---

This e-mail may contain confidential and/or privileged information. If you 
are not the intended recipient (or have received this e-mail in error) 
please notify the sender immediately and destroy this e-mail. Any 
unauthorized copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Type level sets with GADTs, fundeps etc

2008-07-15 Thread J . Burton
At Tue, 15 Jul 2008 10:02:23 -0400,
Jeff Polakow wrote:
[...]
> >
> Type classes are open so there is nothing to prevent you from adding another
> instance for If, perhaps in a different module, which returns some arbitrary
> type.

I see what you mean...so I tried to make Ins return an LSet of
"something", like this:

data LSet t where
Nil :: LSet Nil
Ins :: (Member a t b
  , If b t (a ::: t) r) 
  => L a -> LSet t -> LSet r

/home/jim/sdf-bzr/dsel/TF/Set-July08.hs:44:9:
No instance for (If b t (a ::: t) r)
  arising from a use of `Ins'
   at /home/jim/sdf-bzr/dsel/TF/Set-July08.hs:44:9-11
Possible fix: add an instance declaration for (If b t (a ::: t) r)
In the expression: Ins
In the definition of `insert': insert = Ins

/home/jim/sdf-bzr/dsel/TF/Set-July08.hs:68:6:
Inferred type is less polymorphic than expected
  Quantified type variable `a' is mentioned in the environment:
insert :: L a -> LSet t -> LSet r
  (bound at /home/jim/sdf-bzr/dsel/TF/Set-July08.hs:44:0)
When checking an existential match that binds
t :: L a
The pattern(s) have type(s): LBox
The body has type: LSetBox
In a case alternative: LBox t -> LSetBox (insert t s)
In the expression:
case fromChar c of LBox t -> LSetBox (insert t s)
Failed, modules loaded: none.

> 
> -Jeff
> 
> 
> ---
> 
> This e-mail may contain confidential and/or privileged information. If you
> are not the intended recipient (or have received this e-mail in error)
> please notify the sender immediately and destroy this e-mail. Any
> unauthorized copying, disclosure or distribution of the material in this
> e-mail is strictly forbidden.
> [2  ]
> 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Type level sets with GADTs, fundeps etc

2008-07-15 Thread Jeff Polakow
Hello,

> > > data LSet t where
> > > Nil :: LSet Nil
> > > --either add the new element or do nothing
> > > Ins :: (Member a t b
> > >   , If b (LSet t) (LSet (a ::: t)) r)
> > >   => L a -> LSet t -> r
> > >
> > The constructor Ins needs to return an LSet. Maybe try replacing 
> occurrences of r with (LSet r).
> > 
> 
> I expected that r would be an LSet, as its the output of If which
> returns its 2nd or 3rd argument:
> 
> class If p x y z | p x y -> z
> where if' :: p -> x -> y -> z
> instance If T x y x 
> instance If F x y y 
> 
Type classes are open so there is nothing to prevent you from adding 
another instance for If, perhaps in a different module, which returns some 
arbitrary type.

-Jeff



---

This e-mail may contain confidential and/or privileged information. If you 
are not the intended recipient (or have received this e-mail in error) 
please notify the sender immediately and destroy this e-mail. Any 
unauthorized copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Type level sets with GADTs, fundeps etc

2008-07-15 Thread J . Burton
At Tue, 15 Jul 2008 09:43:40 -0400,
Jeff Polakow wrote:
> Hello,

Hi Jeff,

> 
> > data LSet t where
> > Nil :: LSet Nil
> > --either add the new element or do nothing
> > Ins :: (Member a t b
> >   , If b (LSet t) (LSet (a ::: t)) r)
> >   => L a -> LSet t -> r
> >
> The constructor Ins needs to return an LSet. Maybe try replacing occurrences 
> of r with (LSet r).
> 

I expected that r would be an LSet, as its the output of If which
returns its 2nd or 3rd argument:

class If p x y z | p x y -> z
where if' :: p -> x -> y -> z
instance If T x y x 
instance If F x y y 

Jim
> -Jeff
> 
> ---
> 
> This e-mail may contain confidential and/or privileged information. If you
> are not the intended recipient (or have received this e-mail in error)
> please notify the sender immediately and destroy this e-mail. Any
> unauthorized copying, disclosure or distribution of the material in this
> e-mail is strictly forbidden.
> 
> 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Type level sets with GADTs, fundeps etc

2008-07-15 Thread Jeff Polakow
Hello,

> data LSet t where
> Nil :: LSet Nil
> --either add the new element or do nothing
> Ins :: (Member a t b
>   , If b (LSet t) (LSet (a ::: t)) r) 
>   => L a -> LSet t -> r
>
The constructor Ins needs to return an LSet. Maybe try replacing 
occurrences of r with (LSet r).

-Jeff


---

This e-mail may contain confidential and/or privileged information. If you 
are not the intended recipient (or have received this e-mail in error) 
please notify the sender immediately and destroy this e-mail. Any 
unauthorized copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Type level sets with GADTs, fundeps etc

2008-07-15 Thread J . Burton
I have a problem with applying a type constraint in the 
constructor of a GADT...I wrote some type level code for sets 
using empty types and fundeps, along the lines of Conrad Parker's 
Instant Insanity and Oleg's Lightweight Static Resources. At this 
level things works OK so I have empty types A, B ... Nil with an 
infix cons (:::) and fundeps determining constraints like Member, 
Disjoint etc. (Links to code at the end of message.) Then I can 
evaluate:

> :t insert (undefined::A) (undefined:: A ::: Nil)
insert (undefined::A) (undefined:: A ::: Nil) :: A ::: Nil 

But what I really want to do is wrap this up so that it can be used 
at runtime, not just in the type-checker, so that (just a sketch) 
I could have

insert 'A' empty :: Set (A ::: Nil)

where the runtime value of the set is fully determined by its type. 
I got some help with this and existential boxing seems to be the 
answer. I got a version that uses this strategy working OK until it
comes to applying constraints (e.g. Member, needed when inserting an
element). My problem is below. Here's one with no constraints that 
will type-check:

--
{-box for labels -}
data LBox = forall a. LBox (L a) 
{-box for sets of labels-}
data LSetBox = forall t. LSetBox (LSet t)
{-sets of labels -}
data LSet t where
Nil :: LSet Nil
-- 'dumb' insertion
Ins :: L a -> LSet t -> LSet (a ::: t)
insert = Ins

empty :: LSetBox
empty = LSetBox Nil
 
{-take a Char into a boxed LSet-} 
insertChar :: Char -> LSetBox -> LSetBox
insertChar c (LSetBox s) = 
case fromChar c of
  LBox t -> LSetBox (insert t s)
  
{-populate a box-}
fromChar :: Char -> LBox
fromChar 'A' = LBox AL
{- ... B, etc -- use Template Haskell to generate alphabet and the 
   various instances needed? -}
fromChar _   = error "fromChar: bad Char"


With some Show instances then I can evaluate

> insertChar 'A' empty
LSet {A,}

But what about constraints on the Ins constructor, e.g. on insertion,
ignore elements that are already there:

-
data LSet t where
Nil :: LSet Nil
--either add the new element or do nothing
Ins :: (Member a t b
  , If b (LSet t) (LSet (a ::: t)) r) 
  => L a -> LSet t -> r
insert = Ins

[...]

class Member x ys b | x ys -> b
where member :: x -> ys -> b

instance Member x Nil F 
instance (Eq x y b', Member x ys m, If b' T m b) => 
Member x (y:::ys) b

class If p x y z | p x y -> z
where if' :: p -> x -> y -> z
instance If T x y x 
instance If F x y y 

-

But this evidently isn't the way to use fundeps -- here's
the error:

Malformed constructor result type: r
In the result type of a data constructor: r
In the data type declaration for `LSet'
Failed, modules loaded: none.

(The other place I tried putting the constraints is in the type
of `insert' rather than the Ins constructor...)

How can I express this constraint? BTW, I would rather be using type 
families for this, for forward compatibility and their greater
generality, so if I can also get round this with them I'd love to 
know how...

Thanks, and sorry for the long post!

Jim

[1] Purely type level version: http://jim.sdf-eu.org/TypeLevelSets2.hs
[2] Interactive version using GADTs/Existential boxing: 
http://jim.sdf-eu.org/Set-July08.hs 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Mutually recursive modules and google protocol-buffers

2008-07-15 Thread Max Bolingbroke
> And there is no way ghc can compile these in separate modules.

I may be being redundant here, but you may not know that GHC actually
can compile mutually recursive modules. See
http://www.haskell.org/ghc/docs/latest/html/users_guide/separate-compilation.html#mutual-recursion
. Of course, this is not a great solution either, as creating hs-boot
files is a bit tedious, but at least the option is there.

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


[Haskell-cafe] Mutually recursive modules and google protocol-buffers

2008-07-15 Thread Chris Kuklewicz

I have reached an impasse in designing a Haskell API for the google's
protocol-buffers data language / format. (
http://code.google.com/apis/protocolbuffers/docs/overview.html )

The messages in protobuf are defined in a namespace that nests in the usual
hierarchical OO style that Java encourages.

To avoid namespace conflicts, I made a hierarchy of modules.

But...this is a legal pair protobuf message definitions:


// Test that mutual recursion works.
message TestMutualRecursionA {
  optional TestMutualRecursionB b = 1;
  optional int32 content = 2;
}

message TestMutualRecursionB {
  optional TestMutualRecursionA a = 1;
  optional int32 content = 2;
}


And there is no way ghc can compile these in separate modules.

But the overlap of record accessors names "content" makes defining these
messages in a single module with a common namespace quite verbose.

Any opinions on the least worst way to design this?

--
Chris

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