Re: Forall and type synonyms in GHC 7.0

2010-10-31 Thread Bas van Dijk
On Mon, Nov 1, 2010 at 4:30 AM, Mario Blažević  wrote:
>     Before uploading a new version of my project on Hackage, I decided to
> future-proof it against GHC 7.0. I ran into several compile errors caused by
> the changes in let generalization, but these were easy to fix by adding
> extra type annotations. But then I ran into another problem that I can't fix
> so easily. Here is its trimmed-down reproduction:
>
>> {-# LANGUAGE RankNTypes #-}
>>
>> module Test where
>>
>> data Component c = Component {with :: c}
>>
>> pair1 :: (Bool -> c1 -> c2 -> c3) -> Component c1 -> Component c2 ->
>> Component c3
>> pair1 combinator (Component c1) (Component c2) = Component (combinator
>> True c1 c2)
>>
>> type PairBinder m = forall x y r. (x -> y -> m r) -> m x -> m y -> m r
>>
>> pair2 :: Monad m => (PairBinder m -> c1 -> c2 -> c3) -> Component c1 ->
>> Component c2 -> Component c3
>> pair2 combinator = pair1 (combinator . chooseBinder)
>>
>> chooseBinder :: Monad m => Bool -> PairBinder m
>> chooseBinder right = if right then rightBinder else leftBinder
>>
>> leftBinder :: Monad m => PairBinder m
>> leftBinder f mx my = do {x <- mx; y <- my; f x y}
>>
>> rightBinder :: Monad m => PairBinder m
>> rightBinder f mx my = do {y <- my; x <- mx; f x y}
>
>    The general idea here, if you're intrigued, is that pair1 belongs to a
> generic module that packages things it knows nothing about into Components.
> The remaining definitions belong to a client of the generic module, and
> pair2 is a specialization of pair1 to components that have something to do
> with monads.
>
>    Now this little test compiles fine with GHC 6.12.1, but GHC
> 7.0.0.20101029 reports the following error in the pair2 definition:
>
> TestForall.lhs:13:42:
>     Couldn't match expected type `forall x y r.
>   (x -> y -> m r) -> m x -> m y -> m r'
>     with actual type `(x -> y -> m1 r) -> m1 x -> m1 y -> m1 r'
>     Expected type: Bool -> PairBinder m
>   Actual type: Bool -> (x -> y -> m1 r) -> m1 x -> m1 y -> m1 r
>     In the second argument of `(.)', namely `chooseBinder'
>     In the first argument of `pair1', namely
>   `(combinator . chooseBinder)'
>
>     I've tried adding extra type annotations without making any progress. At
> this point I'm beginning to suspect I ran into a bug in GHC 7.0, but I can't
> find it in GHC Trac; the only ticket that looks similar is #4347, but that
> one works for me. Is this a bug? If not, how do I make my code compile?
>
>
> ___
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users@haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>
>

I had the exact same problem in my regional-pointers package in the
withArray function:

withArray ∷ (Storable α, MonadCatchIO pr)
  ⇒ [α]
  → (∀ s. RegionalPtr α (RegionT s pr) → RegionT s pr β)
  → pr β

 I had to replace the original:

withArray vals = withArrayLen vals ∘ const

with:

withArray vals f = withArrayLen vals $ \_ → f

where:

withArrayLen ∷ (Storable α, MonadCatchIO pr)
⇒ [α]
→ (∀ s. Int → RegionalPtr α (RegionT s pr) → RegionT s pr β)
→ pr β

So unfortunately you gave to inline the function composition:

pair2 combinator = pair1 $ \b -> combinator (chooseBinder b)

Note that in the other thread I'm describing a similar problem in my
usb-safe package. Where in essence the problem is that the following
won't type check:

foo :: (forall s. ST s a) -> a
foo st = ($) runST st

but the following will:

foo :: (forall s. ST s a) -> a
foo st = runST st

and surprisingly the following will also type check:

foo :: (forall s. ST s a) -> a
foo st = runST $ st

Regards,

Bas
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: [Haskell-cafe] Equivalent of withForeignPtr for System.Mem.Weak?

2010-10-31 Thread Antoine Latter
On Sun, Oct 31, 2010 at 10:14 PM, Matthew Steele  wrote:
> I have an object to which I have added one or more finalizers via
> addFinalizer from System.Mem.Weak.  I would like to have a function that
> allows me to make use of the object within a block of IO code, and guarantee
> that the finalizer(s) will not be called during the code block -- sort of
> like withForeignPtr, but for arbitrary objects.  Does such a function exist,
> and if not, how could I write one?
>
> I can imagine writing something like:
>
> \begin{code}
> withObject :: a -> IO b -> IO b
> withObject obj action = do
>  result <- action
>  touchObject obj  -- touchObject :: a -> IO ()
>  return result
> \end{code}
>

CC'ing GHC-users list.

The 'primitive' package has a general purpose 'touch' function:

http://hackage.haskell.org/packages/archive/primitive/0.3.1/doc/html/Control-Monad-Primitive.html#v:touch

But it doesn't state what guarantees are provided by the function.

Antoine
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Forall and type synonyms in GHC 7.0

2010-10-31 Thread Mario Blažević
Before uploading a new version of my project on Hackage, I decided to
future-proof it against GHC 7.0. I ran into several compile errors caused by
the changes in let generalization, but these were easy to fix by adding
extra type annotations. But then I ran into another problem that I can't fix
so easily. Here is its trimmed-down reproduction:

> {-# LANGUAGE RankNTypes #-}
>
> module Test where
>
> data Component c = Component {with :: c}
>
> pair1 :: (Bool -> c1 -> c2 -> c3) -> Component c1 -> Component c2 ->
Component c3
> pair1 combinator (Component c1) (Component c2) = Component (combinator
True c1 c2)
>
> type PairBinder m = forall x y r. (x -> y -> m r) -> m x -> m y -> m r
>
> pair2 :: Monad m => (PairBinder m -> c1 -> c2 -> c3) -> Component c1 ->
Component c2 -> Component c3
> pair2 combinator = pair1 (combinator . chooseBinder)
>
> chooseBinder :: Monad m => Bool -> PairBinder m
> chooseBinder right = if right then rightBinder else leftBinder
>
> leftBinder :: Monad m => PairBinder m
> leftBinder f mx my = do {x <- mx; y <- my; f x y}
>
> rightBinder :: Monad m => PairBinder m
> rightBinder f mx my = do {y <- my; x <- mx; f x y}

   The general idea here, if you're intrigued, is that pair1 belongs to a
generic module that packages things it knows nothing about into Components.
The remaining definitions belong to a client of the generic module, and
pair2 is a specialization of pair1 to components that have something to do
with monads.

   Now this little test compiles fine with GHC 6.12.1, but GHC
7.0.0.20101029 reports the following error in the pair2 definition:

TestForall.lhs:13:42:
Couldn't match expected type `forall x y r.
  (x -> y -> m r) -> m x -> m y -> m r'
with actual type `(x -> y -> m1 r) -> m1 x -> m1 y -> m1 r'
Expected type: Bool -> PairBinder m
  Actual type: Bool -> (x -> y -> m1 r) -> m1 x -> m1 y -> m1 r
In the second argument of `(.)', namely `chooseBinder'
In the first argument of `pair1', namely
  `(combinator . chooseBinder)'

I've tried adding extra type annotations without making any progress. At
this point I'm beginning to suspect I ran into a bug in GHC 7.0, but I can't
find it in GHC Trac; the only ticket that looks similar is #4347, but that
one works for me. Is this a bug? If not, how do I make my code compile?
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: Type error in GHC-7 but not in GHC-6.12.3

2010-10-31 Thread Bas van Dijk
(resending this to the list because this failed yesterday because of
the mailinglist downtime)

On Sat, Oct 30, 2010 at 1:57 AM, Bas van Dijk  wrote:
> I could isolate it a bit more if you want.

And so I did. The following is another instance of the problem I'm
having but set in a more familiar setting:

{-# LANGUAGE RankNTypes #-}

import Control.Monad.ST

foo :: (forall s. ST s a) -> a
foo st = ($) runST st

Couldn't match expected type `forall s. ST s a'
               with actual type `ST s a'
   In the second argument of `($)', namely `st'

Note that: 'foo st = runST st' type checks as expected.

Surprisingly 'foo st = runST $ st' also type checks!

I find the latter surprising because according to the report[1]: e1 op
e2 = (op) e1 e2. So either both should type check or both should fail.

I guess that a RULE somewhere eliminates the ($) before the
type-checker kicks in. I do find that a little strange because I
thought RULES where applied after type checking.

Regards,

Bas

[1] http://www.haskell.org/onlinereport/exps.html#operators
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: network programming with GHC 7

2010-10-31 Thread Brandon S Allbery KF8NH
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 10/28/10 05:16 , Kazu Yamamoto (山本和彦) wrote:
> When I compiled a network server with GHC 7 without the "-threaded"
> option and ran it, I got the following error.
> 
>   file descriptor 5496824 out of range for select (0--1024).

I would be extremely suspicious of memory corruption with an fd that large;
it would indicate a kernel file table several tens of megabytes in size and
a minimum 10MB per-process file table associated with every process (on
Unix, but similar concerns probably apply on Windows).

(Also, I thought the new I/O manager didn't use select(), specifically
because it has annoying limitations like the above.)

- -- 
brandon s. allbery [linux,solaris,freebsd,perl]  allb...@kf8nh.com
system administrator  [openafs,heimdal,too many hats]  allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon university  KF8NH
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkzNwcsACgkQIn7hlCsL25V10ACdE6JOxEcTqbSarM0xnff3Bg7d
9Z0AoLPNWTCfJSF8BG7IDU6/Vghwcr/Q
=Onzb
-END PGP SIGNATURE-
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: ANNOUNCE: GHC 7.0.1 Release Candidate 2

2010-10-31 Thread Isaac Dupree

On 10/30/10 04:43, Bas van Dijk wrote:

Which is to be expected because the Prelude is imported implicitly.


No it's not, because you import Prelude explicitly ("import Prelude   ( 
fromInteger )").  In any Haskell, Prelude is only implicitly imported if 
there are no explicit imports of Prelude in that module. 
http://www.haskell.org/onlinereport/modules.html#sect5.6.1


The only thing that could be called "redundant" is that when you write a 
number, it actually calls the thing defined as GHC.Num.fromInteger -- 
whether or not it has been imported --, which is incidentally the same 
thing as you import in that line "import Prelude ( fromInteger )"; And 
similarly for the other built-in syntax.


-Isaac
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: Fixing LDAP lib compilation on OpenBSD

2010-10-31 Thread Julien Dessaux
Sry guys, it seems that the ml bot messed up with my mail. Here is my
original request :

On Sat, Oct 30, 2010 at 7:28 PM, Julien Dessaux  wrote:

> Hi GHC folks,
>
> I'm using the LDAP lib for one of my projects and I found a problem
> while building it on an OpenBSD system. It wouldn't compile because there is
> a macro named differently in the ldap.h include file. Under linux, this
> macro is named LDAP_X_PROXY_AUTHZ_FAILURE but on OpenBSD (and probably other
> BSD flavours), it's named LDAP_PROXY_AUTHZ_FAILURE.
>
> I attached the diff I wrote in order to compile the lib on OpenBSD, but
> it's not a patch I can submit cause it now won't compile on Linux. How can I
> amend this in order to have a code that would compile on both systems? How
> is it possible to specify such conditional system dependent stuff for a C
> binding?
>
> Thanks in advance for your help,
> --
> Julien Dessaux
>
>
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users