RE: passing Strings with FFI

2001-06-20 Thread Corneliu Popeea


>foreign import "fooble" fooble
>fooble :: PackedString -> Int -> IO Int
>
>type PackedString = ByteArray Int

With the code above I'm getting the following error:

-- Unacceptable argument type in foreign declaration: PackedString
-- When checking declaration:
--  foreign import _ccall "fooble" fooble :: PackedString -> Int -> IO Int

Is there any option that I must include when I launch ghc (I'm very new to 
this compiler, as to Haskell)?
-- I'm trying with "ghc -c -fglasgow-exts test.hs"

Best regards,
Corneliu



___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



Re: GHC version 5.00.2 is available

2001-06-20 Thread Manuel M. T. Chakravarty

"Julian Seward (Intl Vendor)" <[EMAIL PROTECTED]> wrote,

>The (Interactive) Glasgow Haskell Compiler -- version 5.00.2
>   ==
> 
> We are pleased to announce a new patchlevel release of the Glasgow
> Haskell Compiler (GHC), version 5.00.2.

For your installation pleasure, RPM packages built on RedHat
are now available.  Binary packages built for RedHat 7.x are at

  ftp://ftp.cse.unsw.edu.au/pub/users/chak/jibunmaki/i386/ghc-5.00.2-1.i386.rpm
  ftp://ftp.cse.unsw.edu.au/pub/users/chak/jibunmaki/i386/ghc-prof-5.00.2-1.i386.rpm

and those for RedHat 6.2 are at

  ftp://ftp.cse.unsw.edu.au/pub/users/chak/jibunmaki/i386-rh6.2/ghc-5.00.2-1.i386.rpm
  
ftp://ftp.cse.unsw.edu.au/pub/users/chak/jibunmaki/i386-rh6.2/ghc-prof-5.00.2-1.i386.rpm

The ghc-prof-* packages contain optional libraries for
profiling.  The packages for 6.2 are courtesy of Tom Moertel.

The source rpm used to built the above binaries is at

  ftp://ftp.cse.unsw.edu.au/pub/users/chak/jibunmaki/src/ghc-5.00.2-1.src.rpm

If you build from the source rpm using an older version of
GHC, note that you have to build the system twice if you
like to use the interactive environment.  The second build
should use the compiler generated in the first.

Manuel

___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



RE: passing Strings with FFI

2001-06-20 Thread Manuel M. T. Chakravarty

"Julian Seward (Intl Vendor)" <[EMAIL PROTECTED]> wrote,

> | I want to pass a String to a function which is imported from C code:
> | foreign import  "pass" prim_pass :: String -> String
> | The declaration above gives me an error from ghc like "String 
> | type not 
> | supported for imported functions".
> | I thought that String being [Char] should be supported 
> | (somehow like a 
> | definition with "newtype" keyword).
> | Can you tell me how can I pass strings to and from C code, as 
> | simple as 
> | possible (I know about HDirect, but I couldn't make it work 
> | for me: red-hat 
> | 7.1, ghc 5.00)?
> 
> First of all, upgrade to 5.00.2, since it is significantly less
> buggy than 5.00.
> 
> 
> int fooble ( char* str, int n )
> {
>fprintf(stderr, "fooble called: %s %d\n", str, n );
>return 42;
> }
> 
> 
> import PrelByteArr
> import PrelPack   (packString)
> 
> foreign import "fooble" fooble
>fooble :: PackedString -> Int -> IO Int
> 
> type PackedString = ByteArray Int
> 
> main = do n <- fooble (packString "hello, C world") 99
>   putStrLn ("Returned value is " ++ show n)
> 
> For more examples read the compiler sources, at 
> fptools/ghc/compiler/ghci/Linker.lhs.

Actually, the portable way of achieving the same effect with
the new FFI libraries is

  import Foreign
  import CForeign

  foreign import fooble :: CString -> Int -> IO Int

  main = withCStringLen "hello, C world" $ \(strPtr, strLen) -> do
   n <- fooble strPtr strLen
   putStrLn ("Returned value is " ++ show n)

Note that it is not really necessary to pass the length
information explicitly.  The CString will be NUL terminated
and so directly usable by C.  I just wanted to exactly
imitate the cited example.  If you don't need the string
length, the simpler function `withCString' is sufficient.

To marshall a string from C to Haskell land, use the
function `CForeign.peekCString'.

See 

  http://haskell.cs.yale.edu/ghc/docs/latest/set/sec-foreign.html
  http://haskell.cs.yale.edu/ghc/docs/latest/set/sec-cforeign.html

for details.

The principal advantage of using Foreign and CForeign
instead of the Prel* functions is that the former are part
of the Haskell FFI standard that we are working at and so,
for example, are also supported by NHC.

Cheers,
Manuel

___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



Re: GHC core representation

2001-06-20 Thread Josef Svenningsson

[This is a reply to Andrew Tolmachs message to the Haskell list about the
-fext-core flag]

Hi!

Some comments on the -fext-core facility. First I just want to say that
it's a really cool feature. It made me a lot keener to use GHC for program
analysis measurements.

First a question which is not really specific to the -fext-core flag
(which I expect someone of the GHC-people to answer):

* I would like to make GHC generate only the core file and the hi file,
nothing more. However, I haven't found a way of making GHC stop after
outputting the hi file. Being able to do this is useful in some other
cases as well;  I sometimes look at the raw core that comes is printed
with the -ddump* flags. It is often the case that I don't want anything to
be generated then.


OK, here are the comments about the new feature:

* In the grammar:
the productions for the nonterminal Arguments seems to be erronious.
When used as they are they cause tons of shift/reduce conflicts. Having
the following solves to problem (I think this is what you really meant):

Argument arg -> @ aty
 |  aexp

* Speaking of arguments, it would be a nice thing if one could get the
output in A-normal-form. This is done by GHC anyway when converting to STG
and in some cases it would be really useful.

* Exactly when in the compilation process does ghc spit out this info
(when I use -fext-core that is)?  What I am really asking is: which
transformations is applied to the core before it is printed? Knowing this
is pretty important. Being able to control it would be super, and from the
documentation this seems to be a goal.

* A minor point:
The example in the beginning of section 3.6 seems to be incorrect. It
should read:

f :: %forall a . a -> BinTree (BinTree a) =
  \ @a (x::a) -> Leaf @(BinTree a) (Leaf @a x)
   ¯¯¯

OK, I think that's all for now. I'll probarbly come up with some more
questions in a while.

Cheers,

/Josef


___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



RE: GHC version 5.00.2 is available

2001-06-20 Thread Julian Seward (Intl Vendor)


| >  What's new in 5.00.2
| > ==
| >
| [..]
| 
| How about Andrew Tolmach's -fext-core flag? Did it make it 
| into 5.00.2 or do we have to wait for next official release?

No, it didn't.  The 5.00.X line exists purely to give (hopefully)
increasingly stable renditions of what was released as 5.00, and
in particular to fix show-stopping bugs.  All new development 
happens in the CVS "HEAD" branch, which will get snapshotted
into 5.02 at some point.

J

___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



RE: passing Strings with FFI

2001-06-20 Thread Julian Seward (Intl Vendor)


| I want to pass a String to a function which is imported from C code:
|   foreign import  "pass" prim_pass :: String -> String
| The declaration above gives me an error from ghc like "String 
| type not 
| supported for imported functions".
| I thought that String being [Char] should be supported 
| (somehow like a 
| definition with "newtype" keyword).
| Can you tell me how can I pass strings to and from C code, as 
| simple as 
| possible (I know about HDirect, but I couldn't make it work 
| for me: red-hat 
| 7.1, ghc 5.00)?

First of all, upgrade to 5.00.2, since it is significantly less
buggy than 5.00.


int fooble ( char* str, int n )
{
   fprintf(stderr, "fooble called: %s %d\n", str, n );
   return 42;
}


import PrelByteArr
import PrelPack (packString)

foreign import "fooble" fooble
   fooble :: PackedString -> Int -> IO Int

type PackedString = ByteArray Int

main = do n <- fooble (packString "hello, C world") 99
  putStrLn ("Returned value is " ++ show n)

For more examples read the compiler sources, at 
fptools/ghc/compiler/ghci/Linker.lhs.

J

___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



passing Strings with FFI

2001-06-20 Thread Corneliu Popeea

Hello,

I want to pass a String to a function which is imported from C code:
foreign import  "pass" prim_pass :: String -> String
The declaration above gives me an error from ghc like "String type not 
supported for imported functions".
I thought that String being [Char] should be supported (somehow like a 
definition with "newtype" keyword).
Can you tell me how can I pass strings to and from C code, as simple as 
possible (I know about HDirect, but I couldn't make it work for me: red-hat 
7.1, ghc 5.00)?

Best regards,
Corneliu


___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



Re: GHC version 5.00.2 is available

2001-06-20 Thread Josef Svenningsson

On Mon, 18 Jun 2001, Julian Seward (Intl Vendor) wrote:

>
>The (Interactive) Glasgow Haskell Compiler -- version 5.00.2
>   ==
>
[..]

>  What's new in 5.00.2
> ==
>
[..]

How about Andrew Tolmach's -fext-core flag? Did it make it into 5.00.2 or
do we have to wait for next official release?

/Josef


___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users