Shu Wu | 3 Jul 11:23

How to save a haskell data structure in C?

Hey, folks. I've got a problem which I've thought about for days.
I need to write a program that mixes C and haskell code. And the C code controls the procedure. In C code, I want to save a complex data strcuture defined in haskell and pass it back to a haskell function at certain time. Like the following:
in haskell:
   data A = A {...} -- very very complex data structure
  initA :: A
  initA = A {...}
  func :: A -> A
  func a = ... -- return a new 'A'
in C:
  main
  {
     a = initA
     ... take some actions
     a = func a;
     ... take some other actions
     a = func a;
     ...
     ...
   }
Different from most cross-language programs, this C program doesn't alter the data in haskell, just saves it and passes it on. So I'm wondering if there's some convienent way other than marshalling the data in haskell?
BTW, mashalling data requires all work done in IO monad, which will change the program stucture. So I really don't want to mashal it.
Thank you!
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users <at> haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Christiaan Baaij | 2 Jul 12:16

GHC API: How to determine Type.Type equality when using type operators?

Hi all,

I've been doing some work with the GHC API where I translate Haskell  
to VHDL,
and as such I have to translate Haskell Types to VHDL Types. I store the
translations in a Map as such:

-- A orderable equivalent of CoreSyn's Type for use as a map key
newtype OrdType = OrdType { getType :: Type.Type }
instance Eq OrdType where
   (OrdType a) == (OrdType b) = Type.tcEqType a b
instance Ord OrdType where
   compare (OrdType a) (OrdType b) = Type.tcCmpType a b

-- A map of a Core type to the corresponding type name
type TypeMap = Map.Map OrdType (AST.VHDLId, Either AST.TypeDef  
AST.SubtypeIn)

This solution work fine for 'simple' types and ensures that the VHDL  
Type
definitions are all unique. However, a problem rises when type  
operators come
in to play, as Type.tcEqType does not know the 'rules' of these type  
operators
and can thus not infer that two types are equal. Let me give some  
context for
my problem:

We use statically fixed-size vectors instead of lists, as we always  
want to
know the static length of an array. We use a vector implementation  
similar to
Data.Param.FSVec defined in the parameterized-data package [1], except  
that we
use type-level integers from the tfp library [2] to define the static  
vector
lenght. The tfp library support things like type-level multiplication,
something that we use in our vector library.

Now, say we have two bit vectors of length 12 defined as such:

a :: Vector D12 Bit
b :: Vector (D3 :*: D4) Bit

The GHC type checker can infer that 'a' and 'b' are of equal type, as  
it knows
the definitions for the ':*:' multiplication type-operator that is  
defined in
the tfp library. Of course, the only answer Type.tcEqType can give us  
if we
ask if the types of 'a' and 'b' are equals is False, as it does not  
know the
context provided by the type-operator.

So my question is:
Is there a functions in the GHC API that I can use to check the  
equality of
two types given the context provided by certain type operators? I have  
looked
at the Haddock documentation, the GHC Wiki, and the GHC code itself,  
but have
been unable to find such a function.

Regards,
Christiaan

[1] http://hackage.haskell.org/package/parameterized-data
[2] http://hackage.haskell.org/package/tfp
Ian Lynagh | 1 Jul 13:18
Gravatar

ANNOUNCE: GHC 6.10.4 Release Candidate 1


We are pleased to announce the first release candidate for GHC 6.10.4:

    http://www.haskell.org/ghc/dist/6.10.4-rc1/

We have now fixed all the bugs that we intend to fix for 6.10.4, so if
there is a bug that is important to you that hasn't been fixed in the
release candidate, please let us know. The release notes are here:

    http://www.haskell.org/ghc/dist/6.10.4-rc1/release-6-10-4.html

The directory above contains two source bundles:

    ghc-6.10.3.20090628-src.tar.bz2
    ghc-6.10.3.20090628-src-extralibs.tar.bz2

Only the first of these is necessary. The "extralibs" package contains
various extra packages that we normally supply with GHC - unpack the
extralibs tarball on top of the source tree to add them, and they will
be included in the build automatically.

There are also installers for Windows (i386) and OS X (i386), and binary
distributions for x86_64/Linux and i386/Linux. More may appear later.

Please test as much as possible; bugs are much cheaper if we find them
before the release!

Thanks
Ian, on behalf of the GHC team
Simon Marlow | 30 Jun 12:12

6.12.1 planning

Hi Folks,

As usual, we're planning a major release of GHC around September. 
Here's our list of the main items currently scheduled for 6.12.1, and 
their status.  If you have the time and inclination to help with any of 
these, please get involved!

* Parallel performance.  6.12.1 will ship with the improvements to 
parallel performance described in our ICFP 2009 paper.  Still to do: 
overhaul the +RTS GC settings, tune for good performance by default.

* Parallel profiling: the new RTS tracing features will be included, and 
we hope to have a release of ThreadScope to coincide with GHC 6.12.1. 
ThreadScope is written using gtk2hs, and could benefit from someone with 
expertise in producing polished gtk2hs apps - if you can lend a hand, 
contact Satnam Singh <satnams <at> microsoft.com>.

* Unicode I/O: the new Unicode I/O library is in, and will ship with 
6.12.1.  Still to do: decide on the public API for changing encodings 
and newline conversion.

* Shared libraries: we intend to ship with shared library support on at 
least x86/Linux and x86-64/Linux.  There are various tasks remaining to 
do here - Duncan, can we have a summary?

* Data Parallel Haskell.  Manuel, can you comment on the state of play? 
  What can we expect in time for 6.12.1?

* Plugin support in GHC.  The patches are not yet in GHC, and as far as 
I know are awaiting review - Simon, can you say more?

* The new backend code generator.  At the moment, it seems unlikely that 
GHC 6.12.1 will ship with the new code generator enabled by default, 
although it may well be available for testing.  Meanwhile, work on it 
continues.

The smaller items are all embodied in tickets, here are the tickets 
currently in the 6.12.1 milestone (135):

http://hackage.haskell.org/trac/ghc/query?status=new&status=assigned&status=reopened&milestone=6.12.1

and on the 6.12 branch (251):

http://hackage.haskell.org/trac/ghc/query?status=new&status=assigned&status=reopened&milestone=6.12+branch

I estimate there are 2 man years of work here - needless to say, we 
aren't going to fix all these tickets :)  As usual, if you want to vote 
for something, add your email to the CC field of the ticket.

Several of these tickets would make good tasks for a fledgling GHC 
hacker.  e.g.  http://hackage.haskell.org/trac/ghc/ticket/2362 (allow 
full import syntax in GHCi) has a lot of support, and is a nice 
self-contained task (but not a small one).

Even if you're not a GHC hacker you can still help, e.g. by helping to 
narrow down the cause of a bug, or verifying a bug on your platform.

Let me remind people that GHC HEAD has the new build system, and it's 
actually rather pleasant to work with.  Even if you have no idea what 
you're doing, you can always say 'make' at the top level and the build 
system will figure out what needs doing (ok, so that's what build 
systems are supposed to do, but GHC's has never quite managed it until 
now!).

Cheers,
	Simon
Neil Mitchell | 29 Jun 21:58

Re: group keyword with TransformListComp

Hi,

The question of syntax is always something that provokes intense
discussion. My interest (and concern) with the choice of syntax in
this case is three-fold:

1) I want HLint to turn on as many Haskell extensions as possible when
parsing, with the trade off that they don't break a massive number of
existing programs. For each extension I have weighed up the number of
programs that will get broken (because the extension steals previously
valid syntax), vs the number that will be parsed (how popular the
extension is). I've erred on the side of enabling extensions, so am
happy to accept changes in meaning for a!b and $(a). Almost all
extensions get turned on, with the exception of TransformListComp,
which even breaks the source code to HLint itself - something no other
extension does. It seems the syntax stolen is far too much, especially
when compared to other extensions.

2) I want to use TransformListComp in HLint. In particular, I have a
nested pile of group/sort surrounding a list comp that would be
perfect for TransformListComp. However, as it stands, I can't even
enable the extension without that file breaking. I could qualify all
the uses of group, but that seems too much hassle. I'd really like to
enable the extension (without modification), and then start converting
each group-like list-comp one at a time.

3) We'll never be able to make TransformListComp enabled in future
versions of Haskell' since we break too many programs. It's an
extension that is destined forever to remain only an extension. That
seems like a lonely life for an extension.

Thanks

Neil

On Sat, Jun 27, 2009 at 11:52 AM, Max Bolingbroke<omega.theta <at> gmail.com> wrote:
> Hi,
>
> I agree this is annoying. It was hard to find syntax which was both
> meaningful and currently unused, so we settled on this instead. As
> Simon says, suggestions are welcome!
>
> Note that group *should* be parsed as a special id, so you can still
> import D.L qualified and then use dot notation to access the function.
>
> Cheers,
> Max
>
>
> 2009/6/21 Neil Mitchell <ndmitchell <at> gmail.com>:
>> Hi,
>>
>> The TransformListComp extension makes group a keyword. Unfortunately
>> group is a useful function, and is even in Data.List. Thus,
>> Data.List.group and TransformListComp are incompatible. This seems a
>> very painful concession to give up a nice function name for a new
>> extension. Is this intentional? Here's an example:
>>
>>> $ cat GroupKeyword.hs
>>> {-# LANGUAGE TransformListComp #-}
>>> module GroupKeyword where
>>>
>>> a = map head $ group $ sort [1..100]
>>> $ ghci GroupKeyword.hs
>>> GHCi, version 6.10.2: http://www.haskell.org/ghc/  :? for help
>>> Loading package ghc-prim ... linking ... done.
>>> Loading package integer ... linking ... done.
>>> Loading package base ... linking ... done.
>>> [1 of 1] Compiling GroupKeyword     ( GroupKeyword.hs, interpreted )
>>>
>>> GroupKeyword.hs:4:15: parse error on input `group'
>>> Failed, modules loaded: none.
>>> Prelude>
>>
>> There are some places I'd like to use TransformListComp, but I often
>> want to use group in the same module.
>>
>> Thanks
>>
>> Neil
>>
>
Niklas Broberg | 27 Jun 12:44

Proposal: Deprecate ExistentialQuantification

Hi all,

Following the discussion on the use of 'forall' and extensions that
use it [1], I would hereby like to propose that the
ExistentialQuantification extension is deprecated.

My rationale is as follows. With the introduction of GADTs, we now
have two ways to write datatype declarations, the old simple way and
the GADTs way. The GADTs way fits better syntactically with Haskell's
other syntactic constructs, in all ways. The general style is
(somewhat simplified) "keyword type 'where' decls", where keyword can
in Haskell 98 be class or instance, but with GADTs also data. The old
simple way of defining data types is the odd one out. It certainly has
its uses though, in particular when defining some simple (but possibly
large) enum-like datatype (like cabal's Extension type incidentally),
then it obviously becomes tedious to have to restate the trivial type
signature for each constructor.

Using GADTs style syntax it is possible to allow constructors with
existentially quantified arguments with *no additional syntax needed*.
It follows nicely from the standard syntax for type signature
declarations (assuming explicit foralls), e.g. the following "normal"
datatype declaration

  data Foo =
    forall a . Show a => Foo a

which uses ExistentialQuantification syntax, could be written as

  data Foo where
    Foo :: forall a . Show a => a -> Foo

which is syntactically just a normal type signature.

The upside of deprecating ExistentialQuantification is thus that we
keep the syntax cleaner, and we keep the old style of datatype
declarations simple (as it should be, IMO). Anything fancier can use
the GADTs syntax, which anyone that uses something fancier should be
acquainted with anyway.

The downside is that we lose one level of granularity in the type
system. GADTs enables a lot more semantic possibilities for
constructors than ExistentialQuantification does, and baking the
latter into the former means we have no way of specifying that we
*only* want to use the capabilities of ExistentialQuantification.

My own take on that is that what we have now is a wart that should be
removed, and that if we think that the latter is a problem then the
way to go would be to split the monolithic GADTs extension into
several semantic levels. There is of course also the downside that we
break existing code, but that's a standard problem with improvement
through deprecation which I will pay no mind.

Discussion period: 2 weeks

Cheers,

/Niklas

[1] http://www.haskell.org/pipermail/glasgow-haskell-users/2009-June/017432.html
Ahn, Ki Yung | 26 Jun 06:43

Does this, and should this type check on GHC 6.10.x ?

Dear GHC type hackers,

We got a code (please refer to the attached lhs file) that uses type
families and type classes very cleverly.  We don't know who wrote
itbecause this was a contribution of an anonymous reviewer on our paper,
which we are still revising. http://kyagrd.dyndns.org/wiki/SharedSubtypes
Although we learned a lot from this code, we still have unsolved
question about this code.

The problem is, we are still not sure whether this code actually type
checks in any GHC version, and we are not even sure whether this should
type check or not as it is.  I wasn't able to type check this in any of
the GHC versions 6.10.1 on windows and debian linux, GHC 6.10.2 on
windows and debian linux, or GHC 6.10.3 on debian linux.  I also asked
some of my colleagues at my school who has GHC installed to run this
code, but they weren't able to load up either.

However, some people we email conversation with reported that they were
able to successfully load this code in GHC version 6.10.1 in their
system.  This is very surprising because we weren't able to type check
it with the same version (GHC 6.10.1) on our machines (Windows XP and
Debian Linux).  Since there is no reason that GHC type checker would
behave differently among different platforms, the code I am attaching is
still an unsolved misery to us.

It would be very helpful for us if any of can type check this successful
could report what version of GHC on what platform and what GHC command
line options used to make this code type check.  And also, we welcome
any discussion whether this code should or should not in principle type
check.

Thanks in advance,

Ahn, Ki Yung

FYI, I had the following error message when I tried it on ghc 6.10.3.
(When I commented out the problematic line, the last equation of crossB,
I was able to load it up though.  So, this code definitely doesn't seem
to be just thought out of one's mind without actually running on ghc.)

========================================================================

kyagrd <at> kyavaio:~/tmp$ ghci --version
The Glorious Glasgow Haskell Compilation System, version 6.10.3
kyagrd <at> kyavaio:~/tmp$ ghci -fglasgow-exts -XUndecidableInstances
Review3.lhs
GHCi, version 6.10.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main             ( Review3.lhs, interpreted )

Review3.lhs:67:29:
    Could not deduce (Expandable (Tuple (Map ((,) t2) ys)))
      from the context (xs ~ t2 ::: ts2, Expandable t2)
      arising from a use of `:::' at Review3.lhs:67:29-59
    Possible fix:
      add (Expandable (Tuple (Map ((,) t2) ys))) to the context of
        the constructor `:::'
      or add an instance declaration for
         (Expandable (Tuple (Map ((,) t2) ys)))
    In the expression: Bs (mapB x ys) ::: crossB xs ys
    In the definition of `crossB':
        crossB (x ::: xs) ys = Bs (mapB x ys) ::: crossB xs ys
    In the definition of `expandPair':
        expandPair _ pair (a ::: as) (b ::: bs)
                     = crossB (a ::: as) (b ::: bs)
                     where
                         crossB :: BList xs -> BList ys -> BList (Cross
xs ys)
                         crossB Nil ys = Nil
                         crossB (x ::: xs) ys = Bs (mapB x ys) :::
crossB xs ys
                         mapB ::
                           (Expandable x) => Bit x -> BList ys -> BList
(Map ((,) x) ys)
                         mapB x Nil = Nil
                         mapB x (y ::: ys) = pair x y ::: mapB x ys
Failed, modules loaded: none.

Attachment (Review3.lhs): text/x-literate-haskell, 3728 bytes
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users <at> haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Niklas Broberg | 24 Jun 02:32

Proposal: ExplicitForall

Hi all,

(I'm writing this to several lists since it involves GHC
(implementation of extensions), cabal (registration of extensions) and
some future Haskell standard (formalisation of extensions).)

In my quest to implement all known syntactic extensions to Haskell in
my haskell-src-exts package, I've become painfully aware of the
sometimes ad-hoc nature that these extensions have been added to GHC.
This should not be taken as criticism per se, GHC is awesome and I'm
sure a lot of thought and research has gone into all of these
extensions. I think the problem (from my point of view) is rather that
most of the extensions are only really "interesting" on a type system
level, whereas the syntactic level is rather trivial, and thus the
latter has (rightly) gotten far less formal attention. I hope my
putting the light on these issues will be a help and a kickoff towards
improving the state of formalisation of the known and registered (with
Cabal) extensions.

One of the most blatant and (to me) problematic such issues is the
matter of using 'forall'. GHC has a number of extensions relating to
the use of forall-quantified types in various interesting ways. With
none of these extensions on, forall is not considered a keyword, so
the syntax with explicit forall quantification cannot be used at all
('forall' is considered a varid). However, with *any* extension on
that relates to forall-quantified types, forall is a keyword, and can
syntactically be used in types *anywhere*. This doesn't mean all such
types will pass the type checker, most of them won't in fact, but
syntactically there is really no (or at least very little) difference.

Conceptually, all of these extensions (specifically
PolymorphicComponents, Rank2Types, RankNTypes, LiberalTypeSynonyms and
ScopedTypeVariables (and strangely also ExistentialQuantification))
thus have one thing in common. They all enable syntactically
forall-quantified types. They allow different uses of these types as
far as the type system is concerned, but syntactically there is no
difference between type and type (in fact there cannot be, as I
discussed in a recent blog post [1]).

Funnily enough there are also some uses of forall-quantified types
that are common to all of these extensions - using a forall just to
make polymorphism explicit in a type doesn't change anything as far as
the type system is concerned, so e.g. the types '(Eq a) => a -> Bool'
and 'forall a . (Eq a) => a -> Bool' are equivalent. The latter type
can be given to a function when any of the listed six extensions are
given, even if most of them have nothing to do with this at all!

So, what I'm getting at is an idea that Isaac Dupree gave as a comment
to my blog post. He said:

   "I wish there was a plain old ExplicitForall extension that enabled
the keyword in types (without extending the type checker -- only like
(id :: forall a. a -> a) would be allowed)".

I think this is a really great idea. I find it conceptually appealing,
since I think it covers exactly that blind spot that is the seemingly
unintended intersection between all these extensions. And it also
makes the separation of concern between the syntactic level and the
type system more clear. Any formalisation of any of the type system
extensions would not need to bother with syntactic details, but can
simply be said to imply ExplicitForall.

I would thus like to propose the following formalisation of the
ExplicitForall extension:

=========================================
ExplicitForall enables the use of the keyword 'forall' to make a type
explicitly polymorphic. Syntactically, it would mean the following
change to Haskell 98:

* 'forall' becomes a reserved word.
* '.' (dot) becomes a special (not reserved) operator.
* The following syntactic rule changes:

type      -> 'forall' tyvars '.' type
           | context '=>' type
           | ftype

ftype     -> btype '->' type
           | btype

gendecl   -> vars '::' type

It does not allow the use of explicitly polymorphic types in any way
not already allowed by Haskell 98 for implicitly polymorphic types.
=========================================

One thing to note is that I haven't touched the matter of
ExistentialQuantification in the above. Syntactically this is a
different beast entirely, and could well be handled separately, though
it's really an artifact of the way we (by default) write our data type
declarations. Using GADT-style declarations, existential
quantification goes nicely along with the others by following the same
syntactic rules for types, even though from a type system it is of
course still quite different from the rest. But with the ordinary
Haskell 98 declaration style, we could define the syntactic part of
the ExistentialQuantification extension as the following:

=========================================
ExistentialQuantification allows data constructors to take
existentially quantified arguments. Syntactically, it means the
following changes to Haskell98:

* 'forall' becomes a reserved word.
* '.' (dot) becomes a special (not reserved) operator.
* The following syntactic rule changes:

constrs   -> econstr_1 '|' ... '|' econstr_n

econstr   -> ['forall' tyvars '.' [context '=>']] constr

=========================================

My hope is that you'll all agree with me on the need and rationale for
the ExplicitForall extension, and that my proposal for formalisation
is good enough for adoption. I feel much less strongly about
ExistentialQuantification, and would love to hear some more input on
that matter, but I do think it needs to be addressed one way or the
other.

Thoughts?

Cheers,

/Niklas

[1] http://nibrofun.blogspot.com/2009/06/whats-in-forall.html
Bulat Ziganshin | 23 Jun 23:28

wiki page on GHC GC


i have started http://haskell.org/haskellwiki/GHC/Memory_Management -
not much written yet

--

-- 
Best regards,
 Bulat                          mailto:Bulat.Ziganshin <at> gmail.com
Neil Mitchell | 21 Jun 20:12

group keyword with TransformListComp

Hi,

The TransformListComp extension makes group a keyword. Unfortunately
group is a useful function, and is even in Data.List. Thus,
Data.List.group and TransformListComp are incompatible. This seems a
very painful concession to give up a nice function name for a new
extension. Is this intentional? Here's an example:

> $ cat GroupKeyword.hs
> {-# LANGUAGE TransformListComp #-}
> module GroupKeyword where
>
> a = map head $ group $ sort [1..100]
> $ ghci GroupKeyword.hs
> GHCi, version 6.10.2: http://www.haskell.org/ghc/  :? for help
> Loading package ghc-prim ... linking ... done.
> Loading package integer ... linking ... done.
> Loading package base ... linking ... done.
> [1 of 1] Compiling GroupKeyword     ( GroupKeyword.hs, interpreted )
>
> GroupKeyword.hs:4:15: parse error on input `group'
> Failed, modules loaded: none.
> Prelude>

There are some places I'd like to use TransformListComp, but I often
want to use group in the same module.

Thanks

Neil
Ganesh Sittampalam | 20 Jun 22:43

finalizers on handles

Hi,

I recently spent a while debugging a problem where a program deadlocked in 
the non-threaded runtime, but ran fine in the threaded runtime, despite 
the program having no blocking FFI calls, and boiled it down to the 
following test case:

module Main(main) where

import System
import System.IO
import System.Process

main = do
    (ih, oh, _, _) <- runInteractiveProcess "cat" [] Nothing Nothing
    comphszp <- hGetContents oh
    print (length comphszp)
    -- hClose ih -- with this line they both deadlock

The reason for the deadlock is fairly straightforward; since ih isn't 
closed before comphszp is fully demanded, no progress can be made. My 
guess is that the threaded runtime is fine because ih is dead at that 
point, and the finalizer for ih gets a chance to run, closing ih.

If I'm right, is it really sensible for every handle to have this 
finalizer? Closing a pipe has externally visible side 
effects beyond just the release of resources, so it doesn't seem like it 
should happen non-deterministically.

Cheers,

Ganesh

Gmane