Re: [Haskell-cafe] looking for examples of non-full Functional Dependencies

2008-04-16 Thread Martin Sulzmann

Mark P Jones wrote:

Martin Sulzmann wrote:
We're also looking for (practical) examples of "multi-range" 
functional dependencies


class C a b c | c -> a b

Notice that there are multiple (two) parameters in the range of the FD.

It's tempting to convert the above to

class C a b c | c -> a, c -> b

but this yields a weaker (in terms of type improvement) system.


I agree with Iavor.

In fact, the two sets of dependencies that you have given here
are provably equivalent, so it would be decidedly odd to have
a "type improvement" system that distinguishes between them.



Consider

class C a b c | a -> b, a -> c

instance C a b b => C [a] [b] [b]

Suppose we encounter the constraint

C [x] y z

What results can we expect from type improvement?

1) Single-range non-full FDs in GHC following the FD-CHR formulation:

The first FD C a b c | a -> b in combination with
the instance head C [a] [b] [b] will yield

C [x] y z improved by y = [b1] for some b1

A similar reasoning yields

C [x] y z improved by z = [b2] for some b2

So, overall we get

C [x] y z improved by y= [b1] and z = [b2]

Unfortunately, we couldn't establish that b1 and b2 are equal.
Hence, we can *not* apply the instance.

2) Alternative design:

We could now argue that the improvement implied by the FD
is only applicable if we are in the "right" context.

That is,
C [x] y z doesn't yield any improvement because
the context y is still underspecified (doesn't match
the instance).

In case of  C [x] [y] z we get z = [y]
(and C [x] z [y] yields z = [y])


3) Multi-range FDs

Consider

class C a b c | a -> b c

instance C a b b => C [a] [b] [b]

This time it's straightforward.

C [x] y z yields the improvement y = [b] and z = [b]
which then allows us to apply the instance.

4) Summary.

With multi-range FDs we can derive "more" improvement.

C [x] y z   yields y = [b] and z = [b]

Based on the FD-CHR formulation, for the single-range FD case we get

C [x] y z yields y = [b1] and z = [b2]

which is clearly weaker.

The alternative design is even weaker, from C [x] y z we can derive
any improvement.

So, I conclude that in the Haskell type improvement context
there's clearly a difference among single-range and multi-range FDs.

Of course, we could define multi-range FDs in terms of single-range FDs
which then trivially solves the "equivalence" problem (but some user
may be disappointed that their multi-range FDs yield weaker improvement).

Thanks for your pointers below but I believe that FDs in the Haskell context
can be quite different from FDs in the database context.

- Martin



While you're looking for unusual examples of fundeps, you
might also want to consider things like:

  class C a b c | a -> b, b -> c

Note that this is subtly different from a -> b c because

  {a -> b, b -> c}  |=  {a -> b c}

while the reverse does not hold.  Instead of type classes,
I'll give you some more down-to-earth examples of relations
that satisfy these dependencies:

  {Paper, Conference, Year}
  {Professor, University, Country}
  {Person, FavoriteFood, FoodGroup}
  ...

For further insight, you might want to take a look at the theory
of relational databases to see how functional dependencies are
used there.  In that context, some sets of dependencies (such
as {a -> b, b -> c}) can be interpreted as indicators of bad
design.  This, in turn, might give you some ideas about the kinds
of dependencies you can expect to encounter in well-designed
Haskell code.  (Of course, you might still find examples in other
Haskell code of dependencies that would make a database person
wince :-)



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


Re: [Haskell-cafe] export question (GHC.Handle)

2008-04-16 Thread Fraser Wilson
On Thu, Apr 17, 2008 at 2:09 AM, Graham Fawcett <[EMAIL PROTECTED]>
wrote:

> I notice in the source for GHC.Handle that certain functions (e.g.
> fdToHandle_stat) are in the export list, but are not actually exported
> (at least, it seems you cannot import them). What mechanism causes
> these functions to be "hidden", and are they still accessible in some
> way?


Good question.  I often need to export a name to other modules within the
hierarchy, but without making them visible outside it.  I've "solved" this
problem by giving them funky names and adding a comment, but is there a more
structured way to do this?  A quick google hasn't found one yet.

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


[Haskell-cafe] Intro to functional dependencies in Haskell?

2008-04-16 Thread Alexis Hazell
Hi all,

i'm having some trouble 'getting' functional dependencies in the Haskell
context (although my understanding of them in the context of relational
database theory isn't that great either). Could someone please point me
to an introduction / tutorial in this regard? 

Thanks!


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


Re: [Haskell-cafe] looking for examples of non-full Functional Dependencies

2008-04-16 Thread Mark P Jones

Martin Sulzmann wrote:
We're also looking for (practical) examples of "multi-range" functional 
dependencies


class C a b c | c -> a b

Notice that there are multiple (two) parameters in the range of the FD.

It's tempting to convert the above to

class C a b c | c -> a, c -> b

but this yields a weaker (in terms of type improvement) system.


I agree with Iavor.

In fact, the two sets of dependencies that you have given here
are provably equivalent, so it would be decidedly odd to have
a "type improvement" system that distinguishes between them.

While you're looking for unusual examples of fundeps, you
might also want to consider things like:

  class C a b c | a -> b, b -> c

Note that this is subtly different from a -> b c because

  {a -> b, b -> c}  |=  {a -> b c}

while the reverse does not hold.  Instead of type classes,
I'll give you some more down-to-earth examples of relations
that satisfy these dependencies:

  {Paper, Conference, Year}
  {Professor, University, Country}
  {Person, FavoriteFood, FoodGroup}
  ...

For further insight, you might want to take a look at the theory
of relational databases to see how functional dependencies are
used there.  In that context, some sets of dependencies (such
as {a -> b, b -> c}) can be interpreted as indicators of bad
design.  This, in turn, might give you some ideas about the kinds
of dependencies you can expect to encounter in well-designed
Haskell code.  (Of course, you might still find examples in other
Haskell code of dependencies that would make a database person
wince :-)

All the best,
Mark
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Embedding newlines into a string?

2008-04-16 Thread Benjamin L. Russell
Ariel,

In response to your comment, since there was
apparently no section devoted to pitfalls of iterating
over lists, I have added the section "1.4 Iterating
Over a List" in the following HaskellWiki page; viz:

Common Misunderstandings - HaskellWiki
http://www.haskell.org/haskellwiki/Common_Misunderstandings#Iterating_Over_a_List

Hope this helps

Benjamin L. Russell

--- "Benjamin L. Russell" <[EMAIL PROTECTED]>
wrote:

> Ariel,
> 
> Check out the following HaskellWiki pages:
> 
> Common Misunderstandings - HaskellWiki
>
http://www.haskell.org/haskellwiki/Common_Misunderstandings
> 
> Things to avoid - HaskellWiki
> http://www.haskell.org/haskellwiki/Things_to_avoid
> 
> Hope these help
> 
> Benjamin L. Russell
> 
> --- "Ariel J. Birnbaum" <[EMAIL PROTECTED]> wrote:
> 
> > > That's exactly what I was thinking about, but
> your
> > hanoi_shower only
> > > handles list of exactly one action, but you have
> > to handle longer lists,
> > > too. This could be done with explicit recursion
> > 
> > This seems to be a common pitfall for Haskell
> > newcomers: mistaking
> > a single-element list pattern (such as [x]) for a
> > pattern that iterates
> > over every element in the list.
> > I can't seem to find a page with a list of common
> > pitfalls and mistakes...
> > is there such a thing?
> > 
> > -- 
> > Ariel J. Birnbaum
> > ___
> > Haskell-Cafe mailing list
> > Haskell-Cafe@haskell.org
> >
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> > 
> 
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 

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


Re: [Haskell-cafe] Re: Embedding newlines into a string?

2008-04-16 Thread Benjamin L. Russell
Ariel,

Check out the following HaskellWiki pages:

Common Misunderstandings - HaskellWiki
http://www.haskell.org/haskellwiki/Common_Misunderstandings

Things to avoid - HaskellWiki
http://www.haskell.org/haskellwiki/Things_to_avoid

Hope these help

Benjamin L. Russell

--- "Ariel J. Birnbaum" <[EMAIL PROTECTED]> wrote:

> > That's exactly what I was thinking about, but your
> hanoi_shower only
> > handles list of exactly one action, but you have
> to handle longer lists,
> > too. This could be done with explicit recursion
> 
> This seems to be a common pitfall for Haskell
> newcomers: mistaking
> a single-element list pattern (such as [x]) for a
> pattern that iterates
> over every element in the list.
> I can't seem to find a page with a list of common
> pitfalls and mistakes...
> is there such a thing?
> 
> -- 
> Ariel J. Birnbaum
> ___
> 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 types?

2008-04-16 Thread Ryan Ingram
minor correction:

test = and [empty, empty]

On 4/16/08, Ryan Ingram <[EMAIL PROTECTED]> wrote:
> You probably want to look at this:
>   http://wadler.blogspot.com/2008/02/data-types-la-carte.html
> which refers to a paper about this exact problem.
>
> The main types you want are:
>   newtype Fix a = In { out :: a (Fix a) }
>   data (f :+: g) x = Inl (f x) | Inr (g x)
>
> Yes, you end up with a ton of constructors, but you can use typeclass
> machinery and "smart constructors" to help with this problem; see, for
> example, 
> http://www.haskell.org/pipermail/haskell-cafe/2008-February/040098.html
>
> With (:<:) and inj as defined by that post, you can end up with something 
> like:
>
> and :: (t :<: LogicalConnective) => [Fix t] -> Fix t
> and ps = In (inj (And ps))
>
> empty :: (t :<: BasicGoal) => Fix t
> empty = In (inj Empty)
>
> type Problem1 = Fix (LogicalConnective :+: BasicGoal)
>
> test :: Problem1
> test = and empty empty
>
>  -- ryan
>
> On 4/16/08, Ron Alford <[EMAIL PROTECTED]> wrote:
> > Here's the setup:
> > I have a series of problems that use various logical connectives.  The
> > problem is that they're not all the same.  So instead of creating one
> > giant datatype (or duplicating much code), I'd like to assemble them
> > like toy blocks.
> >
> > I've boiled down an example here:
> >
> > data LogicalConnective a =
> >Not a
> >| And [a]
> >| Or [a]
> >
> > data BasicGoal a =
> >Atomic String [Term]
> >| Empty
> >| Logical (LogicalConnective a)
> >deriving (Show, Eq)
> >
> > data PreferenceGoal1 =
> >Basic1 PreferenceGoal1
> >| Prefer1 PreferenceGoal1
> >
> > This works OK, but PreferenceGoal1 is a dead end.  I can't combine it
> > with other connectives.  So I try:
> >
> > data PreferenceGoal2 a =
> >Basic2  (PreferenceGoal2 a)
> >| Prefer2 (PreferenceGoal2 a)
> >
> > And this works fine, but seems impossible to explicitly type (ie,
> > there is nothing to substitute for 'a' in a type declaration).  Or am
> > I wrong?
> >
> > Also, it could be that this is just an ugly way to represent things
> > (it does require a huge number of constructors).  Any suggestions?
> >
> > -Ron
> > ___
> > 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 types?

2008-04-16 Thread Ryan Ingram
You probably want to look at this:
   http://wadler.blogspot.com/2008/02/data-types-la-carte.html
which refers to a paper about this exact problem.

The main types you want are:
   newtype Fix a = In { out :: a (Fix a) }
   data (f :+: g) x = Inl (f x) | Inr (g x)

Yes, you end up with a ton of constructors, but you can use typeclass
machinery and "smart constructors" to help with this problem; see, for
example, http://www.haskell.org/pipermail/haskell-cafe/2008-February/040098.html

With (:<:) and inj as defined by that post, you can end up with something like:

and :: (t :<: LogicalConnective) => [Fix t] -> Fix t
and ps = In (inj (And ps))

empty :: (t :<: BasicGoal) => Fix t
empty = In (inj Empty)

type Problem1 = Fix (LogicalConnective :+: BasicGoal)

test :: Problem1
test = and empty empty

  -- ryan

On 4/16/08, Ron Alford <[EMAIL PROTECTED]> wrote:
> Here's the setup:
> I have a series of problems that use various logical connectives.  The
> problem is that they're not all the same.  So instead of creating one
> giant datatype (or duplicating much code), I'd like to assemble them
> like toy blocks.
>
> I've boiled down an example here:
>
> data LogicalConnective a =
>Not a
>| And [a]
>| Or [a]
>
> data BasicGoal a =
>Atomic String [Term]
>| Empty
>| Logical (LogicalConnective a)
>deriving (Show, Eq)
>
> data PreferenceGoal1 =
>Basic1 PreferenceGoal1
>| Prefer1 PreferenceGoal1
>
> This works OK, but PreferenceGoal1 is a dead end.  I can't combine it
> with other connectives.  So I try:
>
> data PreferenceGoal2 a =
>Basic2  (PreferenceGoal2 a)
>| Prefer2 (PreferenceGoal2 a)
>
> And this works fine, but seems impossible to explicitly type (ie,
> there is nothing to substitute for 'a' in a type declaration).  Or am
> I wrong?
>
> Also, it could be that this is just an ugly way to represent things
> (it does require a huge number of constructors).  Any suggestions?
>
> -Ron
> ___
> 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] C++ interface with Haskell

2008-04-16 Thread Isaac Dupree

perhaps

haskell:
foreign export "foo_func" foo :: Int -> IO Int
-- I forget the rest of the syntax here

C++:

extern "C" {
int foo_func(int i);
}

int some_cplusplus_function() {
  int bat = 3;
  int blah = foo_func(bat);
  return blah;
}


Is that all you need to do?


Miguel Lordelo wrote:

Hi all,

Well...somehow I'm a beginner in Haskell. But actually my interest in
Haskell will increase if it is possible to call a haskell function in C++.
Something like GreenCard ( http://www.haskell.org/greencard/ ) simplifying
the task of interfacing Haskell programs to external libraries (usually).
But is there also a task to interface a foreign language with Haskell, but
calling Haskell functions. Or c2hs which is an interface generator that
simplifies the development of Haskell bindings to C libraries.

I want to know this, because in my company some guys are doing some testing
with Frotran and MatLab and I want to show them the power of haskell and the
software which we are using is implemented in C++ (there is the reason to
make Haskel -> C++).

I read somewhere that the only way for C++ calling a haskell function is to
create a binding between Haskell and C and from C to C++, but a easy "Hello
World" example was not there.
Unfortunatelly I couldn't found anything usefull, like an complete example,
or how to compile the code from haskell to C to C++.

Can sombody help me, please :P

Chears,
Miguel Lordelo.





___
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] Re: I/O system brokenness with named pipes

2008-04-16 Thread Richard A. O'Keefe

One question is whether the program is statically or dynamically linked,
and if the latter, whether it is possible (as it is in many Unices) to
slide your own open(2) definition in between the program and the system
library.  If it is, it's possible to slide in something that fakes
/dev/stdin.

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


[Haskell-cafe] export question (GHC.Handle)

2008-04-16 Thread Graham Fawcett
I notice in the source for GHC.Handle that certain functions (e.g.
fdToHandle_stat) are in the export list, but are not actually exported
(at least, it seems you cannot import them). What mechanism causes
these functions to be "hidden", and are they still accessible in some
way?

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


Re: [Haskell-cafe] looking for examples of non-full Functional Dependencies

2008-04-16 Thread Dan Weston

I think I was the one confused.

I guess I was (falsely) thinking that both

  C Int  Char T
  C Char Int  T

could both be instances of class C a b c | c -> a, c -> b but only one 
could be an instance of C a b c | c -> a b.


Sorry for adding noise to the discussion.

Ryan Ingram wrote:

I'm still confused about this point:

On 4/16/08, Dan Weston <[EMAIL PROTECTED]> wrote:

 class C a b c | c -> a b

 Notice that there are multiple (two) parameters in the range of the FD.

 It's tempting to convert the above to

 class C a b c | c -> a, c -> b

 but this yields a weaker (in terms of type improvement) system.


In both cases the statement is that given a type x, the instance C x y
z for some y,z and the constraint C x a b, we unambiguously have a ~
y, b ~ z (where ~ is type equality)

How does the order in (c -> a b) matter?

  -- ryan




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


Re: [Haskell-cafe] Hoogle

2008-04-16 Thread John Goerzen
On Wednesday 16 April 2008 6:16:56 pm Brandon S. Allbery KF8NH wrote:
> On Apr 16, 2008, at 17:30 , John Goerzen wrote:
> > On Wed April 16 2008 3:54:45 pm Galchin, Vasili wrote:
> >>I already found this link. Thanks in any case. I want to
> >> O_CREATE a
> >> file, i.e. do a openFd creating a new file. O_CREATE should be the
> >> FileMode, but I don't see in the link below.
> >
> > Indeed.  It seems there is no way to pass O_CREAT to openFile.
> > there is
> > createFile, but that's really a different call.  Sigh.
>
> Remember, Haskell is functional; treat the function to call as an
> argument?

I don't have access to the GHC source just at the moment, but presumably that 
is an interface to creat() instead of open().  creat() is documented as:

   creat()   is   equivalent   to   open()withflagsequal
to
   O_CREAT|O_WRONLY|O_TRUNC.


There could be reasons that you would want to pass, say, O_CREAT|O_RDWR|
O_APPEND and omit O_TRUNC.

There are also reasons that you might want to pass, say, O_WRONLY|O_APPEND 
with no O_CREAT.  The fact that openFile implies O_CREAT sometimes is a 
serious misfeature IMHO.  That means bug.

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


[Haskell-cafe] Mutually recursive types?

2008-04-16 Thread Ron Alford
Here's the setup:
I have a series of problems that use various logical connectives.  The
problem is that they're not all the same.  So instead of creating one
giant datatype (or duplicating much code), I'd like to assemble them
like toy blocks.

I've boiled down an example here:

data LogicalConnective a =
Not a
| And [a]
| Or [a]

data BasicGoal a =
Atomic String [Term]
| Empty
| Logical (LogicalConnective a)
deriving (Show, Eq)

data PreferenceGoal1 =
Basic1 PreferenceGoal1
| Prefer1 PreferenceGoal1

This works OK, but PreferenceGoal1 is a dead end.  I can't combine it
with other connectives.  So I try:

data PreferenceGoal2 a =
Basic2  (PreferenceGoal2 a)
| Prefer2 (PreferenceGoal2 a)

And this works fine, but seems impossible to explicitly type (ie,
there is nothing to substitute for 'a' in a type declaration).  Or am
I wrong?

Also, it could be that this is just an ugly way to represent things
(it does require a huge number of constructors).  Any suggestions?

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


Re: [Haskell-cafe] Hoogle

2008-04-16 Thread Brandon S. Allbery KF8NH


On Apr 16, 2008, at 17:30 , John Goerzen wrote:

On Wed April 16 2008 3:54:45 pm Galchin, Vasili wrote:
   I already found this link. Thanks in any case. I want to  
O_CREATE a

file, i.e. do a openFd creating a new file. O_CREATE should be the
FileMode, but I don't see in the link below.


Indeed.  It seems there is no way to pass O_CREAT to openFile.   
there is

createFile, but that's really a different call.  Sigh.


Remember, Haskell is functional; treat the function to call as an  
argument?


--
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] Re: I/O system brokenness with named pipes

2008-04-16 Thread Simon Marlow

Donn Cave wrote:

I have run into this problem, with Network.Socket (socket).  If I 
remember right,
ktrace showed me what was happening.  This isn't my favorite thing about 
Haskell.

Is there even a means provided to set it back to blocking?


There isn't a way right now to open a file using a blocking FD, however 
the IO library does support using blocking FDs (the std handles are left 
in blocking mode to avoid causing problems with pipes).  We could 
certainly add an interface to let you open files in blocking mode - just 
submit a feature request via GHC's Trac and we'll try to get around to 
it (or better still, send us a patch... the code is in 
GHC.Handle.fdToHandle).


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


Re: [Haskell-cafe] looking for examples of non-full Functional Dependencies

2008-04-16 Thread Ryan Ingram
I'm still confused about this point:

On 4/16/08, Dan Weston <[EMAIL PROTECTED]> wrote:
> > >  class C a b c | c -> a b
> > >
> > >  Notice that there are multiple (two) parameters in the range of the FD.
> > >
> > >  It's tempting to convert the above to
> > >
> > >  class C a b c | c -> a, c -> b
> > >
> > >  but this yields a weaker (in terms of type improvement) system.

In both cases the statement is that given a type x, the instance C x y
z for some y,z and the constraint C x a b, we unambiguously have a ~
y, b ~ z (where ~ is type equality)

How does the order in (c -> a b) matter?

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


Re: [Haskell-cafe] Hoogle

2008-04-16 Thread Graham Fawcett
On Wed, Apr 16, 2008 at 5:30 PM, John Goerzen <[EMAIL PROTECTED]> wrote:
> On Wed April 16 2008 3:54:45 pm Galchin, Vasili wrote:
>  > hi Antoine,
>  >
>  >I already found this link. Thanks in any case. I want to O_CREATE a
>  > file, i.e. do a openFd creating a new file. O_CREATE should be the
>  > FileMode, but I don't see in the link below.
>
>  Indeed.  It seems there is no way to pass O_CREAT to openFile.  there is
>  createFile, but that's really a different call.  Sigh.

In openFile, in GHC 6.8.2 at least, O_CREAT is passed for WriteMode
and ReadWriteMode -- see output_flags in GHC/Handle.hs.

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


Re: [Haskell-cafe] Hoogle

2008-04-16 Thread John Goerzen
On Wed April 16 2008 3:54:45 pm Galchin, Vasili wrote:
> hi Antoine,
>
>I already found this link. Thanks in any case. I want to O_CREATE a
> file, i.e. do a openFd creating a new file. O_CREATE should be the
> FileMode, but I don't see in the link below.

Indeed.  It seems there is no way to pass O_CREAT to openFile.  there is 
createFile, but that's really a different call.  Sigh.

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


Re: [Haskell-cafe] Hoogle

2008-04-16 Thread Neil Mitchell
Hi Vasili,

>I already found this link. Thanks in any case. I want to O_CREATE a file,
> i.e. do a openFd creating a new file. O_CREATE should be the FileMode, but I
> don't see in the link below.

What do you want to do beyond writeFile/openFile/readFile? If you can,
its better to use the standard IO openFile.

Thanks

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


Re: [Haskell-cafe] Hoogle

2008-04-16 Thread Galchin, Vasili
hi Antoine,

   I already found this link. Thanks in any case. I want to O_CREATE a file,
i.e. do a openFd creating a new file. O_CREATE should be the FileMode, but I
don't see in the link below.

Thanks, Vasili

On Wed, Apr 16, 2008 at 1:46 PM, Antoine Latter <[EMAIL PROTECTED]> wrote:

> 2008/4/16 Galchin, Vasili <[EMAIL PROTECTED]>:
>  > Hello,
> >
> >   I tried d to use Hoogle to find openFd's signature and more
> > importantly FileMode. I found FileMode which is  a type synonym with
> CMode.
> > I don't understand what are the "values" for FileMode (so I can call
> > openFd). ??
>
> Values of type FileMode are defined in System.Posix.Files
>
> See
> http://haskell.org/ghc/docs/latest/html/libraries/unix/System-Posix-Files.html#1
> for the defintions.
>
> Does that help?
>
> -Antoine
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Shim: finding modules

2008-04-16 Thread Graham Fawcett
Hi folks, I'm a newbie, so please forgive any terminological mistakes.

I've been using Shim in Emacs with great success, but there's one
issue I've encountered, and I don't know if it's configuration problem
or something fundamental. Consider a module 'App' and submodules
'App.Front' and 'App.Back'. When editing code in App that depends on
the submodules, Shim works well at resolving the location of the
submodules, and validates my code. But when editing App.Front, which
depends on App.Back, Shim fails to validate -- my working directory is
App.Front, and Shim doesn't seem able to find the location of
App.Back.

I'd like to be able to tell Shim that 'App' is the root of my project,
and to locate modules from that root. Is this possible?

On a related note, it seems that Shim is moribund (though others have
forked it, mostly for Vim support?). Given its utility, I'm surprised
by this. Do you have other support tools that serve a similar role? (I
know of haskell-mode, but the GHC API integration seems to be the
feature that sets Shim apart.)

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


Re: [Haskell-cafe] Re: Embedding newlines into a string?

2008-04-16 Thread Ariel J. Birnbaum
> That's exactly what I was thinking about, but your hanoi_shower only
> handles list of exactly one action, but you have to handle longer lists,
> too. This could be done with explicit recursion

This seems to be a common pitfall for Haskell newcomers: mistaking
a single-element list pattern (such as [x]) for a pattern that iterates
over every element in the list.
I can't seem to find a page with a list of common pitfalls and mistakes...
is there such a thing?

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


Re: [Haskell-cafe] ANN: datapacker 1.0.0

2008-04-16 Thread Brandon S. Allbery KF8NH


On Apr 16, 2008, at 14:08 , Marc Weber wrote:

src/System/IO/Binary.hs:266:8:
Illegal signature in pattern: ForeignPtr CChar
Use -XPatternSignatures to permit it

Hackage confirms this build failure:
http://hackage.haskell.org/packages/archive/MissingH/1.0.1/logs/ 
failure/ghc-6.8


Should not be hard to fix :) just add it to the Cabal file as  
extension :)

  extensions:
PatternSignatures


You might want to see previous messages today, about how hackage is  
forcing MissingH to be either 6.6 or 6.8 compatible but not both.


--
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


Re: [Haskell-cafe] Hoogle

2008-04-16 Thread Neil Mitchell
Hi

>   I tried d to use Hoogle to find openFd's signature and more
> importantly FileMode.

Hoogle does not search the Posix library, because in general people
should steer clear of it - otherwise I won't be able to run your
programs :-) - The next version of Hoogle will permit selecting to
search the Posix library, if you so choose.

> I found FileMode which is  a type synonym with CMode.
> I don't understand what are the "values" for FileMode (so I can call
> openFd). ??

Clearly, the documentation is rather weak. It comes from the Posix
"open" function, which is document all over the place, and you can see
the code here: 
http://darcs.haskell.org/ghc-6.6/packages/unix/System/Posix/IO.hsc

After figuring out what you want, I recommend submitting a patch for
documentation. Additionally, if what you want can be done in a cross
platform way, but lacks the appropriate abstraction layer, I would add
a request for this to be fixed.

Thanks

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


Re: [Haskell-cafe] Hoogle

2008-04-16 Thread Antoine Latter
2008/4/16 Galchin, Vasili <[EMAIL PROTECTED]>:
> Hello,
>
>   I tried d to use Hoogle to find openFd's signature and more
> importantly FileMode. I found FileMode which is  a type synonym with CMode.
> I don't understand what are the "values" for FileMode (so I can call
> openFd). ??

Values of type FileMode are defined in System.Posix.Files

See 
http://haskell.org/ghc/docs/latest/html/libraries/unix/System-Posix-Files.html#1
for the defintions.

Does that help?

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


[Haskell-cafe] Hoogle

2008-04-16 Thread Galchin, Vasili
Hello,

  I tried d to use Hoogle to find openFd's signature and more
importantly FileMode. I found FileMode which is  a type synonym with CMode.
I don't understand what are the "values" for FileMode (so I can call
openFd). ??

Thanks,

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


Re: [Haskell-cafe] Wrong Answer Computing Graph Dominators

2008-04-16 Thread Bertram Felgenhauer
Denis Bueno wrote:
> I'm using the Data.Graph.Inductive.Query.Dominators library
> (http://haskell.org/ghc/docs/latest/html/libraries/fgl/Data-Graph-Inductive-Query-Dominators.html)
> with GHC 6.8.2.
>  The library is a bit spare on comments, so I may or may not be using
> it correctly.
> 
[snip]
> But what I am getting is:
>--> uips = [-9,20]
>--> domConfl = [2,-9,20]
>--> domAssigned = [-2,-9,-12,20]
>--> lastd = 20
> 
> But -9 is not a dominator for 2, since 20,-7,8,6,2 is a path from 20
> to 2 that does not touch 9.  -9 is also not a dominator for -2, since
> 20,-7,8,6,-2 is a path from 20 to -2 not touching 9.
> 
> Am I missing something?

No. Data.Graph.Inductive.Query.Dominators is just buggy.

1) domr is meant to find a fixed point of builddoms by iteratively
   applying builddoms, but in fact it calls builddoms at most twice.
2) the code doesn't handle nodes with no predecessors correctly.

Here's a quick fix:

diff -rN -u old-fgl/Data/Graph/Inductive/Query/Dominators.hs 
new-fgl/Data/Graph/Inductive/Query/Dominators.hs
--- old-fgl/Data/Graph/Inductive/Query/Dominators.hs2008-04-16 
20:13:35.0 +0200
+++ new-fgl/Data/Graph/Inductive/Query/Dominators.hs2008-04-16 
20:13:35.0 +0200
@@ -18,13 +18,13 @@
 builddoms :: DomSets -> [Node] -> DomSets
 builddoms ds [] = ds
 builddoms ds (v:vs) = builddoms ((fs++[(n,p,sort(n:idv))])++(tail rs)) vs
-  where idv = intersection (getdomv p ds)
-(n,p,_) = head rs
+  where idv = intersection ((q \\ [n]):getdomv p ds)
+(n,p,q) = head rs
 (fs,rs) = span (\(x,_,_)->x/=v) ds
 
 domr :: DomSets -> [Node] -> DomSets
 domr ds vs|xs == ds  = ds
-  |otherwise = builddoms xs vs
+  |otherwise = domr xs vs
where xs = (builddoms ds vs)
 
 {-|

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


Re: [Haskell-cafe] ANN: datapacker 1.0.0

2008-04-16 Thread John Goerzen
On Wed April 16 2008 1:08:08 pm Marc Weber wrote:
> > src/System/IO/Binary.hs:266:8:
> > Illegal signature in pattern: ForeignPtr CChar
> > Use -XPatternSignatures to permit it
> >
> > Hackage confirms this build failure:
> > http://hackage.haskell.org/packages/archive/MissingH/1.0.1/logs/failure/
> >ghc-6.8
>
> Should not be hard to fix :) just add it to the Cabal file as extension :)
>   extensions:
> PatternSignatures
>
> Don't worry, be happy *g*

Drat.  my workaround to the hackage issue I described in another thread was 
faulty.  I'm uploading a new version now.

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


Re: [Haskell-cafe] Re: I/O system brokenness with named pipes

2008-04-16 Thread John Goerzen
On Wed April 16 2008 12:20:37 pm Brandon S. Allbery KF8NH wrote:
> On Apr 16, 2008, at 11:16 , John Goerzen wrote:
> > On 2008-04-15, Joe Buehler <[EMAIL PROTECTED]> wrote:
> >> John Goerzen wrote:
> >>> So I have a need to write data to a POSIX named pipe (aka FIFO).
> >>> Long
> >>> story involving a command that doesn't have an option to read data
> >>> from stdin, but can from a named pipe.
> >>
> >> How about /dev/stdin?
> >
> > Only works on Linux.
>
> Hm.  I see it even on our ancient Solaris 8 boxes.  And I'm quite
> sure the *BSDs support it as well.  Just how ancient / weird is this
> "POSIX" platform of yours?


OK, so I shouldn't have said "it only works on Linux", but as far as I can 
tell, it isn't standard (defined by POSIX).  I don't presently have easy 
access to non-Linux machines, but I do want to be as portable as possible.

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


Re: [Haskell-cafe] ANN: datapacker 1.0.0

2008-04-16 Thread Marc Weber
> src/System/IO/Binary.hs:266:8:
> Illegal signature in pattern: ForeignPtr CChar
> Use -XPatternSignatures to permit it
> 
> Hackage confirms this build failure:
> http://hackage.haskell.org/packages/archive/MissingH/1.0.1/logs/failure/ghc-6.8

Should not be hard to fix :) just add it to the Cabal file as extension :)
  extensions: 
PatternSignatures

Don't worry, be happy *g*

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


Re: [Haskell-cafe] looking for examples of non-full Functional Dependencies

2008-04-16 Thread Dan Weston

Iavor Diatchki wrote:

Hello,

On Wed, Apr 16, 2008 at 8:06 AM, Martin Sulzmann
<[EMAIL PROTECTED]> wrote:

We're also looking for (practical) examples of "multi-range" functional
dependencies

 class C a b c | c -> a b

 Notice that there are multiple (two) parameters in the range of the FD.

 It's tempting to convert the above to

 class C a b c | c -> a, c -> b

 but this yields a weaker (in terms of type improvement) system.


Could you elaborate on this?  I think that a system that distinguishes
these two would be very confusing.   If you think of the FDs as
logical statements about what is known of type variables, then the FDs
on the two classes correspond to equivalent logical statements, so I
am not sure why would we distinguish them for improvement purposes.
Also, it seems fairly easy to convert between the two forms purely
based on syntax, so if the one somehow results in better improvements,
why would we ever use the other one?


The two are not isomorphic. The first one c -> a b contains an explicit 
order (class parameter order is significant), whereas the second does 
not (the FDs form a set). I think the isomorphic functional dependency 
in the first case would be the set of all FDs under permutation of class 
parameters, in this case: c -> a b, c -> b a



As for examples of interesting uses of functional dependencies,
perhaps the literature on relational databases would provide some?


Elaborating on the relational connection, it seems at first blush that

class C a b c | a -> b

is not ideally normalized and might presumably be profitably broken up into

class A a b | a -> b
class A a b => B a b c

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


Re: [Haskell-cafe] Re: I/O system brokenness with named pipes

2008-04-16 Thread Donn Cave


On Apr 16, 2008, at 10:25 AM, Brandon S. Allbery KF8NH wrote:


On Apr 16, 2008, at 13:23 , Miguel Mitrofanov wrote:

You are insulting other Unixes. It works on Mac OS X, for example.


Not just that, but IIRC Linux was late to the party:  Solaris got / 
dev/fd/ and /dev/stdin before Linux got /proc/$$/fd/ (which gets  
symlinked to /dev/fd/).


Yeah, among people who don't know much about UNIX, Linux gets a lot  
of credit for things it borrowed.  But /dev/stdin isn't a standard  
feature of UNIX, if you count AIX for example as a UNIX platform.   
And apparently you can compile Haskell programs on AIX - thanks to  
the original poster in this thread's work with GHC - so there you go.


Donn

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


Re: [Haskell-cafe] looking for examples of non-full Functional Dependencies

2008-04-16 Thread Iavor Diatchki
Hello,

On Wed, Apr 16, 2008 at 8:06 AM, Martin Sulzmann
<[EMAIL PROTECTED]> wrote:
> We're also looking for (practical) examples of "multi-range" functional
> dependencies
>
>  class C a b c | c -> a b
>
>  Notice that there are multiple (two) parameters in the range of the FD.
>
>  It's tempting to convert the above to
>
>  class C a b c | c -> a, c -> b
>
>  but this yields a weaker (in terms of type improvement) system.

Could you elaborate on this?  I think that a system that distinguishes
these two would be very confusing.   If you think of the FDs as
logical statements about what is known of type variables, then the FDs
on the two classes correspond to equivalent logical statements, so I
am not sure why would we distinguish them for improvement purposes.
Also, it seems fairly easy to convert between the two forms purely
based on syntax, so if the one somehow results in better improvements,
why would we ever use the other one?

As for examples of interesting uses of functional dependencies,
perhaps the literature on relational databases would provide some?

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


Re: [Haskell-cafe] ANN: datapacker 1.0.0

2008-04-16 Thread Denis Bueno
On Wed, Apr 16, 2008 at 12:02 AM, John Goerzen <[EMAIL PROTECTED]> wrote:
> Hi,
>
>  I'm pleased to announce the first release of datapacker.

Your datapacker depends on MissingH 1.0.1 which, although on hackage,
fails to build with GHC 6.8.2.  (It may build with earlier versions,
but I haven't tried.)

It says:

[41 of 48] Compiling System.IO.Binary ( src/System/IO/Binary.hs,
dist/build/System/IO/Binary.o )

src/System/IO/Binary.hs:115:12:
Illegal signature in pattern: ForeignPtr Word8
Use -XPatternSignatures to permit it

src/System/IO/Binary.hs:266:8:
Illegal signature in pattern: ForeignPtr CChar
Use -XPatternSignatures to permit it

Hackage confirms this build failure:
http://hackage.haskell.org/packages/archive/MissingH/1.0.1/logs/failure/ghc-6.8


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


Re: [Haskell-cafe] Re: I/O system brokenness with named pipes

2008-04-16 Thread Brandon S. Allbery KF8NH


On Apr 16, 2008, at 13:23 , Miguel Mitrofanov wrote:

You are insulting other Unixes. It works on Mac OS X, for example.


Not just that, but IIRC Linux was late to the party:  Solaris got / 
dev/fd/ and /dev/stdin before Linux got /proc/$$/fd/ (which gets  
symlinked to /dev/fd/).


--
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


Re: [Haskell-cafe] Re: I/O system brokenness with named pipes

2008-04-16 Thread Miguel Mitrofanov

You are insulting other Unixes. It works on Mac OS X, for example.

On 16 Apr 2008, at 19:16, John Goerzen wrote:

On 2008-04-15, Joe Buehler <[EMAIL PROTECTED]> wrote:

John Goerzen wrote:

So I have a need to write data to a POSIX named pipe (aka FIFO).   
Long

story involving a command that doesn't have an option to read data
from stdin, but can from a named pipe.


How about /dev/stdin?


Only works on Linux.

-- John

___
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] Re: I/O system brokenness with named pipes

2008-04-16 Thread Brandon S. Allbery KF8NH


On Apr 16, 2008, at 11:16 , John Goerzen wrote:

On 2008-04-15, Joe Buehler <[EMAIL PROTECTED]> wrote:

John Goerzen wrote:

So I have a need to write data to a POSIX named pipe (aka FIFO).   
Long

story involving a command that doesn't have an option to read data
from stdin, but can from a named pipe.


How about /dev/stdin?


Only works on Linux.


Hm.  I see it even on our ancient Solaris 8 boxes.  And I'm quite  
sure the *BSDs support it as well.  Just how ancient / weird is this  
"POSIX" platform of yours?


--
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


Re: [Haskell-cafe] Module for parsing C (pre-processed header files only)?

2008-04-16 Thread Don Stewart
magnus:
>On Wed, Apr 16, 2008 at 4:01 PM, Don Stewart <[EMAIL PROTECTED]> wrote:
> 
>  magnus:
>  >Is there such a beast out there?
>  >
>  >If this were a list on some OO language I'd ask for something that
>  created
>  >an AST and then offered an API based around a visitor pattern.
>  >
>  >The pre-processor (platform specific most likely, but could be
>  cpphs of
>  >course) would be run prior to the tool I'm considering writing.
>   After
>  >that I only need access to declarations of C functions and
>  definitions of
>  >types (structs, enums, other typedefs).
>  >
>  >I had a quick look at the code in c2hs yesterday, but found it a
>  little
>  >hard to make heads or tails of it without some guidance, so I
>  couldn't
>  >tell whether it would be suitable.  Would it?
>  >
>  >Any help or pointers appreciated.
> 
>  I think the main option for parsing C now is the c2hs parser -- there's
>  a summer of code project to wrap it up as a suitable C manipulation,
>  printing and parsing library, so we should see a good standalone
>  solution in a few months.
> 
>Will it be delivered with good documentation? ;-)
> 
>This is /very/ interesting for me and my job (what I'm talking about above
>is not for work though).  I would love to see something that would allow
>me to spend more time using Haskell while being paid for it :-)
> 

Exactly, its potentially a new leading project for Haskell, if we do a
good job here. An exciting niche waiting to be exploited.

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


Re: [Haskell-cafe] Module for parsing C (pre-processed header files only)?

2008-04-16 Thread Magnus Therning
On Wed, Apr 16, 2008 at 4:01 PM, Don Stewart <[EMAIL PROTECTED]> wrote:

> magnus:
> >Is there such a beast out there?
> >
> >If this were a list on some OO language I'd ask for something that
> created
> >an AST and then offered an API based around a visitor pattern.
> >
> >The pre-processor (platform specific most likely, but could be cpphs
> of
> >course) would be run prior to the tool I'm considering writing.
>  After
> >that I only need access to declarations of C functions and
> definitions of
> >types (structs, enums, other typedefs).
> >
> >I had a quick look at the code in c2hs yesterday, but found it a
> little
> >hard to make heads or tails of it without some guidance, so I
> couldn't
> >tell whether it would be suitable.  Would it?
> >
> >Any help or pointers appreciated.
>
> I think the main option for parsing C now is the c2hs parser -- there's
> a summer of code project to wrap it up as a suitable C manipulation,
> printing and parsing library, so we should see a good standalone
> solution in a few months.


Will it be delivered with good documentation? ;-)

This is /very/ interesting for me and my job (what I'm talking about above
is not for work though).  I would love to see something that would allow me
to spend more time using Haskell while being paid for it :-)

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


[Haskell-cafe] Re: I/O system brokenness with named pipes

2008-04-16 Thread John Goerzen
On 2008-04-15, Joe Buehler <[EMAIL PROTECTED]> wrote:
> John Goerzen wrote:
>
>> So I have a need to write data to a POSIX named pipe (aka FIFO).  Long
>> story involving a command that doesn't have an option to read data
>> from stdin, but can from a named pipe.
>
> How about /dev/stdin?

Only works on Linux.

-- John

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


Re[2]: [Haskell-cafe] looking for examples of non-full Functional Dependencies

2008-04-16 Thread Bulat Ziganshin
Hello Martin,

Wednesday, April 16, 2008, 7:06:07 PM, you wrote:

i'm not 100% sure that you'll find there appropriate examples but i
suggest you too look into http://haskell.org/haskellwiki/Library/Streams
where i've used very sophisticated (for me) FDs

> We're also looking for (practical) examples of "multi-range" functional
> dependencies

class C a b c | c ->> a b

> Notice that there are multiple (two) parameters in the range of the FD.

> It's tempting to convert the above to

class C a b c | c ->> a, c -> b

> but this yields a weaker (in terms of type improvement) system.

> Thanks,
>  Martin



> Tom Schrijvers wrote:
>> Hello,
>>
>> I'm looking for practical examples of non-full functional dependencies 
>> and would be grateful if anyone could show me some or point to 
>> applications using them.
>>
>> A non-full functional dependency is one involves only part of the 
>> parameters of a type class. E.g.
>>
>> class C a b c | a -> b
>>
>> has a non-full functional dependency a -> b which does not involve c.
>>
>> Thanks,
>>
>> Tom
>>
>> -- 
>> Tom Schrijvers
>>
>> Department of Computer Science
>> K.U. Leuven
>> Celestijnenlaan 200A
>> B-3001 Heverlee
>> Belgium
>>
>> tel: +32 16 327544
>> e-mail: [EMAIL PROTECTED]
>> url: http://www.cs.kuleuven.be/~toms/
>> ___
>> 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


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


Re: [Haskell-cafe] looking for examples of non-full Functional Dependencies

2008-04-16 Thread Ross Paterson
On Wed, Apr 16, 2008 at 04:30:27PM +0200, Tom Schrijvers wrote:
> I'm looking for practical examples of non-full functional dependencies 
> and would be grateful if anyone could show me some or point to 
> applications using them.
>
> A non-full functional dependency is one involves only part of the  
> parameters of a type class. E.g.
>
>   class C a b c | a -> b
>
> has a non-full functional dependency a -> b which does not involve c.

hackageDB has a substantial sample of code these days, which is handy
for questions like this.  There are examples of non-full FDs in the
following packages:

ArrayRef-0.1.2
arrows-0.4
OpenAFP-1.0
parsec-3.0.0
StrategyLib-4.0.0.0
Yampa-0.9.2.1

However for most of these there are indirect dependencies.  The only
exceptions I can find are those in ArrayRef, parsec and StrategyLib.

On Wed, Apr 16, 2008 at 05:06:07PM +0200, Martin Sulzmann wrote:
> We're also looking for (practical) examples of "multi-range" functional
> dependencies
>
> class C a b c | c -> a b

Look in

BerkeleyDB-0.3
CC-delcont-0.2
collections-0.3
HsJudy-0.2
yi-0.3
yi-gtk-0.2
yi-vty-0.2
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] looking for examples of non-full Functional Dependencies

2008-04-16 Thread Martin Sulzmann
We're also looking for (practical) examples of "multi-range" functional 
dependencies


class C a b c | c -> a b

Notice that there are multiple (two) parameters in the range of the FD.

It's tempting to convert the above to

class C a b c | c -> a, c -> b

but this yields a weaker (in terms of type improvement) system.

Thanks,
Martin



Tom Schrijvers wrote:

Hello,

I'm looking for practical examples of non-full functional dependencies 
and would be grateful if anyone could show me some or point to 
applications using them.


A non-full functional dependency is one involves only part of the 
parameters of a type class. E.g.


class C a b c | a -> b

has a non-full functional dependency a -> b which does not involve c.

Thanks,

Tom

--
Tom Schrijvers

Department of Computer Science
K.U. Leuven
Celestijnenlaan 200A
B-3001 Heverlee
Belgium

tel: +32 16 327544
e-mail: [EMAIL PROTECTED]
url: http://www.cs.kuleuven.be/~toms/
___
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] Module for parsing C (pre-processed header files only)?

2008-04-16 Thread Don Stewart
magnus:
>Is there such a beast out there?
> 
>If this were a list on some OO language I'd ask for something that created
>an AST and then offered an API based around a visitor pattern.
> 
>The pre-processor (platform specific most likely, but could be cpphs of
>course) would be run prior to the tool I'm considering writing.  After
>that I only need access to declarations of C functions and definitions of
>types (structs, enums, other typedefs).
> 
>I had a quick look at the code in c2hs yesterday, but found it a little
>hard to make heads or tails of it without some guidance, so I couldn't
>tell whether it would be suitable.  Would it?
> 
>Any help or pointers appreciated.

I think the main option for parsing C now is the c2hs parser -- there's
a summer of code project to wrap it up as a suitable C manipulation,
printing and parsing library, so we should see a good standalone
solution in a few months.

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


Re: [Haskell-cafe] compressed pointers?

2008-04-16 Thread Don Stewart
ketil:
> 
> One of the downsides of a 64-bit environment is the increased size of
> pointers.  This means that the cost of a String increases from
> something like 12 bytes per char to something like 24.
> 
> I notice BEA uses something called "compressed pointers" to get the
> 64-bit (more registers, etc) benefits without paying the
> (cache-thrashing) cost.
> 
>   
> http://e-docs.bea.com/jrockit/releases/5026x/relnotes/relnotes.html#wp1079760
> 
> Something for GHC?
> 

One small upside (performance wise), is that the bottom 3 bits of the
pointer are now used to encode the constructor on 64 bits, so 'case' gets a
good percent cheaper.

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


Re: [Haskell-cafe] C++ interface with Haskell

2008-04-16 Thread Dan Mead
write the C wrapper that calls haskell, then link that to your C++ objects

I think what you're really asking is how to call C from C++

-Dan

2008/4/16 Miguel Lordelo <[EMAIL PROTECTED]>:

> Hi all,
>
> Well...somehow I'm a beginner in Haskell. But actually my interest in
> Haskell will increase if it is possible to call a haskell function in C++.
> Something like GreenCard ( http://www.haskell.org/greencard/ ) simplifying
> the task of interfacing Haskell programs to external libraries (usually).
> But is there also a task to interface a foreign language with Haskell, but
> calling Haskell functions. Or c2hs which is an interface generator that
> simplifies the development of Haskell bindings to C libraries.
>
> I want to know this, because in my company some guys are doing some
> testing with Frotran and MatLab and I want to show them the power of haskell
> and the software which we are using is implemented in C++ (there is the
> reason to make Haskel -> C++).
>
> I read somewhere that the only way for C++ calling a haskell function is
> to create a binding between Haskell and C and from C to C++, but a easy
> "Hello World" example was not there.
> Unfortunatelly I couldn't found anything usefull, like an complete
> example, or how to compile the code from haskell to C to C++.
>
> Can sombody help me, please :P
>
> Chears,
> Miguel Lordelo.
> ___
> 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] looking for examples of non-full Functional Dependencies

2008-04-16 Thread Tom Schrijvers

Hello,

I'm looking for practical examples of non-full functional dependencies and 
would be grateful if anyone could show me some or point to applications 
using them.


A non-full functional dependency is one involves only part of the 
parameters of a type class. E.g.


class C a b c | a -> b

has a non-full functional dependency a -> b which does not involve c.

Thanks,

Tom

--
Tom Schrijvers

Department of Computer Science
K.U. Leuven
Celestijnenlaan 200A
B-3001 Heverlee
Belgium

tel: +32 16 327544
e-mail: [EMAIL PROTECTED]
url: http://www.cs.kuleuven.be/~toms/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Searching for possible PhD supervisors/projects

2008-04-16 Thread Ivan Miljenovic
Next year, I'm thinking of going overseas (I'm currently in Australia)
to do a PhD.  Preferably, I'd like to do something in the area of
computational combinatorics using Haskell.  Does anyone know of any
particular unis/supervisors I should be looking at/talking to about
this?

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


Re: [Haskell-cafe] Funny State monad dependency

2008-04-16 Thread Hans Aberg

On 16 Apr 2008, at 15:14, Miguel Mitrofanov wrote:

Before somebody noticed: I'm wrong.

It's not List monad, but also a "(->) x" monad, also defined in  
Control.Monad.


Therefore, "return y" is just "const y". Therefore,

x >>= (return y) = x >>= (const y) = x >> y


Right. It is an interesting monad, but it may cause unexpected  
effect, in view of its implicit name.


  Hans


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


Re: [Haskell-cafe] Funny State monad dependency

2008-04-16 Thread Hans Aberg

On 16 Apr 2008, at 15:22, Daniel Fischer wrote:

The point is the

instance Monad ((->) a) where
return x = const x
f >>= g = \x -> g (f x) x

which is defined in Control.Monad.Instances...


Thank you. I suspected there was an instance somewhere, and I wanted  
to know where it is defined.



  (try in GHCI:
Prelude> let f x y = x >>= (return y)
Prelude> :t f
f :: (Monad ((->) a), Monad m) => m a -> m b -> m b
).


It works in Hugs too. If I don't import Control.Monad.State, then
  f :: (Monad a, Monad ((->) b)) => a b -> a c -> a c


This is imported into Control.Monad.State and hence the instance is
visible.

By the type of (>>=), (return y) must have type (a -> m b), on the  
other hand,
if y has type c, then (return y) has type (m' c) for some monad m'.  
Unifying

m' c and a -> m b gives then m' === ((->) a) and c === m b.
Now according to the instance, return y === const y, so f is the  
same as

g x y = x >>= (const y).


Good to know the details. Thanks.

  Hans


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


Re: [Haskell-cafe] Funny State monad dependency

2008-04-16 Thread Daniel Fischer
Am Mittwoch, 16. April 2008 14:56 schrieb Hans Aberg:
> When I load the State module in Hugs, then I can define the function
> f below, but I do not immediately see exactly what function "return"
> returns. Explanation welcome.
>
> For example:
>> f [2..4] [6..9]
>
>[6,7,8,9,6,7,8,9,6,7,8,9]
> That is, it just repeats the second argument as many times as the
> length of the second argument.
>
>Hans Aberg
>
> 
> import Control.Monad.State
>
> f :: Monad a => a b -> a c -> a c
> f x y = x >>= (return y)
> 
>
The point is the

instance Monad ((->) a) where
return x = const x
f >>= g = \x -> g (f x) x

which is defined in Control.Monad.Instances  (try in GHCI:
Prelude> let f x y = x >>= (return y)
Prelude> :t f
f :: (Monad ((->) a), Monad m) => m a -> m b -> m b
). This is imported into Control.Monad.State and hence the instance is 
visible.

By the type of (>>=), (return y) must have type (a -> m b), on the other hand, 
if y has type c, then (return y) has type (m' c) for some monad m'. Unifying 
m' c and a -> m b gives then m' === ((->) a) and c === m b.

Now according to the instance, return y === const y, so f is the same as
g x y = x >>= (const y).
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Funny State monad dependency

2008-04-16 Thread Roberto Zunino

Miguel Mitrofanov wrote:
It has nothing to do with State; it actually works in List monad. 
"return y" is just another way of writing "[y]".


Actually, it seems that in this case return is from the ((->) a) monad, 
i.e. return=const.


f x y = x >>= return y
  = x >>= const y
  = (concat . map) (const y) x
  = concat (map (const y) x)

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


Re: [Haskell-cafe] Funny State monad dependency

2008-04-16 Thread Miguel Mitrofanov

Before somebody noticed: I'm wrong.

It's not List monad, but also a "(->) x" monad, also defined in  
Control.Monad.


Therefore, "return y" is just "const y". Therefore,

x >>= (return y) = x >>= (const y) = x >> y


On 16 Apr 2008, at 17:04, Miguel Mitrofanov wrote:
It has nothing to do with State; it actually works in List monad.  
"return y" is just another way of writing "[y]".


You don't need to import Control.Monad.State for this to work; you  
only need Control.Monad (which is imported by the former).


On 16 Apr 2008, at 16:56, Hans Aberg wrote:
When I load the State module in Hugs, then I can define the  
function f below, but I do not immediately see exactly what  
function "return" returns. Explanation welcome.


For example:
> f [2..4] [6..9]
[6,7,8,9,6,7,8,9,6,7,8,9]
That is, it just repeats the second argument as many times as the  
length of the second argument.


Hans Aberg


import Control.Monad.State

f :: Monad a => a b -> a c -> a c
f x y = x >>= (return y)


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


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


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


Re: [Haskell-cafe] Funny State monad dependency

2008-04-16 Thread Miguel Mitrofanov
It has nothing to do with State; it actually works in List monad.  
"return y" is just another way of writing "[y]".


You don't need to import Control.Monad.State for this to work; you  
only need Control.Monad (which is imported by the former).


On 16 Apr 2008, at 16:56, Hans Aberg wrote:
When I load the State module in Hugs, then I can define the function  
f below, but I do not immediately see exactly what function "return"  
returns. Explanation welcome.


For example:
 > f [2..4] [6..9]
 [6,7,8,9,6,7,8,9,6,7,8,9]
That is, it just repeats the second argument as many times as the  
length of the second argument.


 Hans Aberg


import Control.Monad.State

f :: Monad a => a b -> a c -> a c
f x y = x >>= (return y)


___
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] Funny State monad dependency

2008-04-16 Thread Hans Aberg
When I load the State module in Hugs, then I can define the function  
f below, but I do not immediately see exactly what function "return"  
returns. Explanation welcome.


For example:
  > f [2..4] [6..9]
  [6,7,8,9,6,7,8,9,6,7,8,9]
That is, it just repeats the second argument as many times as the  
length of the second argument.


  Hans Aberg


import Control.Monad.State

f :: Monad a => a b -> a c -> a c
f x y = x >>= (return y)


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


Re: [Haskell-cafe] compressed pointers?

2008-04-16 Thread Jan-Willem Maessen


On Apr 16, 2008, at 4:45 AM, Ketil Malde wrote:

I notice BEA uses something called "compressed pointers" to get the
64-bit (more registers, etc) benefits without paying the
(cache-thrashing) cost.


But only if you're not *actually* using a 64-bit address space.  From  
their own documentation:


The heap size will be limited to less than 4 GB; therefore, you can  
only use this option for applications that demand less than 4 GB of  
live data. The heap will be reduced to meet this size limitation if  
you specify a larger initial (-Xms) or maximum (-Xmx) heap size.


(http://edocs.bea.com/jrockit/jrdocs/refman/optionXX.html#wp1021022)

So this amounts to saying "we can use the 64-bit ISA but still use 32- 
bit pointers with all the restrictions that accompany them".  You  
might be able to keep non-heap data around in excess of 4GB (eg it  
might be possible to mmap a file *and* have 4GB of heap data, and  
maybe even keep thread stacks off-heap as well).


You can take advantage of pointer alignment to get address spaces of  
8-32GB (by shifting 32-bit pointers before dereferencing them), but  
that requires taking back the pointer bits that GHC just stole for  
pointer tagging.


-Jan

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


Re: [Haskell-cafe] monadic debugging

2008-04-16 Thread pepe


On 16/04/2008, at 0:53, Galchin, Vasili wrote:


Hello,

 I have an Linux executable of my Haskell library and test case.  
I see there are several debuggers, e.g. Buddha, Hat, etc. Which  
debugger is currently preferred for monadic (imperative) code? Thanks.


Vasili



For debugging IO code, I have used the GHCi debugger with great  
success in several occasions.

Particularly, :steplocal is very useful in monadic code.
Make sure you read at least the documentation in GHC docs, and the  
tutorial recently published in The Monad Reader.
The latest version of the debugger in HEAD is extended to print the  
contents of IORefs automatically, which you may find useful too.


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


[Haskell-cafe] compressed pointers?

2008-04-16 Thread Ketil Malde

One of the downsides of a 64-bit environment is the increased size of
pointers.  This means that the cost of a String increases from
something like 12 bytes per char to something like 24.

I notice BEA uses something called "compressed pointers" to get the
64-bit (more registers, etc) benefits without paying the
(cache-thrashing) cost.

  http://e-docs.bea.com/jrockit/releases/5026x/relnotes/relnotes.html#wp1079760

Something for GHC?

-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


[Haskell-cafe] C++ interface with Haskell

2008-04-16 Thread Miguel Lordelo
Hi all,

Well...somehow I'm a beginner in Haskell. But actually my interest in
Haskell will increase if it is possible to call a haskell function in C++.
Something like GreenCard ( http://www.haskell.org/greencard/ ) simplifying
the task of interfacing Haskell programs to external libraries (usually).
But is there also a task to interface a foreign language with Haskell, but
calling Haskell functions. Or c2hs which is an interface generator that
simplifies the development of Haskell bindings to C libraries.

I want to know this, because in my company some guys are doing some testing
with Frotran and MatLab and I want to show them the power of haskell and the
software which we are using is implemented in C++ (there is the reason to
make Haskel -> C++).

I read somewhere that the only way for C++ calling a haskell function is to
create a binding between Haskell and C and from C to C++, but a easy "Hello
World" example was not there.
Unfortunatelly I couldn't found anything usefull, like an complete example,
or how to compile the code from haskell to C to C++.

Can sombody help me, please :P

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


[Haskell-cafe] Re: GC'ing file handles and other resources

2008-04-16 Thread Peter Hercek

Abhay Parvate wrote:
I am not saying that it should claim it as soon as it is unused; all I 
am saying that as soon as a priority object becomes unreferenced, it 
should be the first choice for collecting in the next collect.
Further I was under the impression (I may be wrong) that it uses a 
generational GC and therefore scans allocated memory incrementally; not 
the whole at a time. Please correct me if I am wrong.




It would be hard to separate memory collection from handle collection.
 But what could be done is start GC not only when memory consumption
 reaches some threshold but also when handle consumption reaches some
 (other) threshold. I'm curious whether it would work :-)

Peter.

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


Re: Re[4]: [Haskell-cafe] GC'ing file handles and other resources

2008-04-16 Thread Abhay Parvate
Thanks, both for the summary and for the link. Will try to go through it.

Regards,
Abhay

On Wed, Apr 16, 2008 at 12:37 PM, Bulat Ziganshin <[EMAIL PROTECTED]>
wrote:

> Hello Abhay,
>
> Wednesday, April 16, 2008, 10:51:07 AM, you wrote:
>
> > I am not saying that it should claim it as soon as it is unused;
> > all I am saying that as soon as a priority object becomes
> > unreferenced, it should be the first choice for collecting in the next
> collect.
>
> on the GC, all unreferenced objects are collected. there is no
> difference which ones will be collected first - anyway program is
> stopped until whole GC will be finished
>
> > Further I was under the impression (I may be wrong) that it uses a
> > generational GC and therefore scans allocated memory incrementally;
> > not the whole at a time. Please correct me if I am wrong.
>
> yes, it uses generational GC. data are first allocated in small 256k block
> and when it is filled, GC for this small block occurs. data that are
> still alive then moved to the global heap. this minor GC doesn't scan
> global heap. if it will do this, each minor GC will become as slow as
> major ones
>
> "Generational garbage collection for Haskell"
> http://research.microsoft.com/~simonpj/Papers/gen-gc-for-haskell.ps.gz
>
> >
> > Regards,
> > Abhay
>
> > On Wed, Apr 16, 2008 at 11:55 AM, Bulat Ziganshin
> > <[EMAIL PROTECTED]> wrote:
> >  Hello Abhay,
> >
> >  Wednesday, April 16, 2008, 9:30:34 AM, you wrote:
> >
> >  i think it will not work with current ghc GC - it scans entire
> >  memory/nursery when garbage collected so anyway you will need to wait
> >  until next GC event occurs
> >
>
>  >> Your mail gives me an idea, though I am not an iota familiar with
>  >> compiler/garbage collector internals. Can we have some sort of
>  >> internally maintained priority associated with allocated objects?
>  >> The garbage collector should look at these objects first when it
>  >> tries to free anything. The objects which hold other system
>  >> resources apart from memory, such as file handles, video memory, and
>  >> so on could be allocated as higher priority objects. Is such a thing
> possible?
>  >>
>  >> 2008/4/16 Conal Elliott <[EMAIL PROTECTED]>:
>  >>  Are Haskell folks satisfied with the practical necessity of
>  >> imperatively & explicitly reclaiming resources such as file handles,
>  >> fonts & brushes, video memory chunks, etc?  Doesn't explicit freeing
>  >> of these resources have the same modularity and correctness problems
>  >> as explicit freeing of system memory (C/C++ programming)?
>  >>
>  >> I wrote a lovely purely functional graphics library that used video
>  >> memory to lazily compute and cache infinite-resolution images, and I
>  >> found that I don't know how to get my finalizers to run anytime soon
>  >> after video memory chunks become inaccessible.  Explicit freeing
>  >> isn't an option, since the interface is functional, not imperative
> (IO).
>  >>
>  >> I guess I'm wondering a few things:
> >
>  >> * Are Haskell programmers generally content with imperative and
>  >> bug-friendly interfaces involving explicit freeing/closing of
> resources?
>  >> * Do people assume that these resources (or handling them frugally)
>  >> aren't useful in purely functional interfaces?
>  >>  * Are there fundamental reasons why GC algorithms cannot usefully
>  >> apply to resources like video memory, file descriptors, etc?
>  >> * Are there resource management techniques that have the
>  >> flexibility, efficiency, and accuracy of GC that I could be using for
> these other resources?
>  >>
>  >> Thanks,
>  >>   - Conal
> >
>  >> 2008/4/14 Abhay Parvate <[EMAIL PROTECTED]>:
>  >>  Hello,
> >
>  >> In describing the Handle type, the GHC documentation says (in the
> System.IO documentation):
> >
>  >> GHC note: a Handle will be automatically closed when the garbage
>  >> collector detects that it has become unreferenced by the program.
>  >> However, relying on this behaviour is not generally recommended:
>  >> the garbage collector is unpredictable.  If possible, use explicit
>  >> an explicit hClose to close Handles when they are no longer
>  >> required.  GHC does not currently attempt to free up file
>  >> descriptors when they have run out, it is your responsibility to
>  ensure that this doesn't happen.
> >
>  >> But one cannot call hClose on Handles on which something like
>  >> hGetContents has been called; it just terminates the character list
>  >> at the point till which it has already read. Further the manual says
>  >> that hGetContents puts the handle in the semi-closed state, and
> further,
>  >>
>  >> A semi-closed handle becomes closed:
>  >>  if hClose is applied to it;  if an I/O error occurs when reading
>  >> an item from the handle;  or once the entire contents of the handle
> has been read.
>  >> So do I safely assume here, according to the third point above,
>  >> that it

Re[4]: [Haskell-cafe] GC'ing file handles and other resources

2008-04-16 Thread Bulat Ziganshin
Hello Abhay,

Wednesday, April 16, 2008, 10:51:07 AM, you wrote:

> I am not saying that it should claim it as soon as it is unused;
> all I am saying that as soon as a priority object becomes
> unreferenced, it should be the first choice for collecting in the next 
> collect.

on the GC, all unreferenced objects are collected. there is no
difference which ones will be collected first - anyway program is
stopped until whole GC will be finished

> Further I was under the impression (I may be wrong) that it uses a
> generational GC and therefore scans allocated memory incrementally;
> not the whole at a time. Please correct me if I am wrong.

yes, it uses generational GC. data are first allocated in small 256k block
and when it is filled, GC for this small block occurs. data that are
still alive then moved to the global heap. this minor GC doesn't scan
global heap. if it will do this, each minor GC will become as slow as
major ones

"Generational garbage collection for Haskell"
http://research.microsoft.com/~simonpj/Papers/gen-gc-for-haskell.ps.gz

>  
> Regards,
> Abhay

> On Wed, Apr 16, 2008 at 11:55 AM, Bulat Ziganshin
> <[EMAIL PROTECTED]> wrote:
>  Hello Abhay,
>  
>  Wednesday, April 16, 2008, 9:30:34 AM, you wrote:
>  
>  i think it will not work with current ghc GC - it scans entire
>  memory/nursery when garbage collected so anyway you will need to wait
>  until next GC event occurs
>  

 >> Your mail gives me an idea, though I am not an iota familiar with
 >> compiler/garbage collector internals. Can we have some sort of
 >> internally maintained priority associated with allocated objects?
 >> The garbage collector should look at these objects first when it
 >> tries to free anything. The objects which hold other system
 >> resources apart from memory, such as file handles, video memory, and
 >> so on could be allocated as higher priority objects. Is such a thing 
 >> possible?
 >>
 >> 2008/4/16 Conal Elliott <[EMAIL PROTECTED]>:
 >>  Are Haskell folks satisfied with the practical necessity of
 >> imperatively & explicitly reclaiming resources such as file handles,
 >> fonts & brushes, video memory chunks, etc?  Doesn't explicit freeing
 >> of these resources have the same modularity and correctness problems
 >> as explicit freeing of system memory (C/C++ programming)?
 >>
 >> I wrote a lovely purely functional graphics library that used video
 >> memory to lazily compute and cache infinite-resolution images, and I
 >> found that I don't know how to get my finalizers to run anytime soon
 >> after video memory chunks become inaccessible.  Explicit freeing
 >> isn't an option, since the interface is functional, not imperative (IO).
 >>
 >> I guess I'm wondering a few things:
>  
 >> * Are Haskell programmers generally content with imperative and
 >> bug-friendly interfaces involving explicit freeing/closing of resources?
 >> * Do people assume that these resources (or handling them frugally)
 >> aren't useful in purely functional interfaces?
 >>  * Are there fundamental reasons why GC algorithms cannot usefully
 >> apply to resources like video memory, file descriptors, etc?
 >> * Are there resource management techniques that have the
 >> flexibility, efficiency, and accuracy of GC that I could be using for these 
 >> other resources?
 >>
 >> Thanks,
 >>   - Conal
>  
 >> 2008/4/14 Abhay Parvate <[EMAIL PROTECTED]>:
 >>  Hello,
>  
 >> In describing the Handle type, the GHC documentation says (in the System.IO 
 >> documentation):
>  
 >> GHC note: a Handle will be automatically closed when the garbage
 >> collector detects that it has become unreferenced by the program.
 >> However, relying on this behaviour is not generally recommended:
 >> the garbage collector is unpredictable.  If possible, use explicit
 >> an explicit hClose to close Handles when they are no longer
 >> required.  GHC does not currently attempt to free up file
 >> descriptors when they have run out, it is your responsibility to  ensure 
 >> that this doesn't happen.
>  
 >> But one cannot call hClose on Handles on which something like
 >> hGetContents has been called; it just terminates the character list
 >> at the point till which it has already read. Further the manual says
 >> that hGetContents puts the handle in the semi-closed state, and further,
 >>
 >> A semi-closed handle becomes closed:
 >>  if hClose is applied to it;  if an I/O error occurs when reading
 >> an item from the handle;  or once the entire contents of the handle has 
 >> been read.
 >> So do I safely assume here, according to the third point above,
 >> that it's fine if I do not call hClose explicitly as far as I am
 >> consuming all the contents returned by hGetContents?
>  
 >> Thanks,
 >> Abhay
 >>
 >> ___
 >>  Haskell-Cafe mailing list
 >> [EMAIL PROTECTED]
 >>  http://www.haskell.org/mailman/listinfo/haskell-cafe
 >>
>  
>  
 >>
 >> ___
 >>  Haskell-Cafe mailing