Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Diagnosing : Large memory usage + low CPU (Edward Z. Yang)
   2.  FFI export lazy list of string (Alexander.Vladislav.Popov )
   3.  Compiling shared (dll) library (Alexander.Vladislav.Popov )


----------------------------------------------------------------------

Message: 1
Date: Mon, 05 Dec 2011 01:29:17 -0500
From: "Edward Z. Yang" <ezy...@mit.edu>
Subject: Re: [Haskell-beginners] Diagnosing : Large memory usage + low
        CPU
To: Hugo Ferreira <h...@inescporto.pt>
Cc: beginners <beginners@haskell.org>
Message-ID: <1323066469-sup-4667@ezyang>
Content-Type: text/plain; charset=UTF-8

Excerpts from Hugo Ferreira's message of Fri Dec 02 05:57:00 -0500 2011:
> I have attached a profiling session (showing types).
> I am surprised to see that the "[]" consumes so much data.
> Where is this coming from? Need to analyse this more closely.

For an -hT profile, what that actually means is your lists are using lots
of memory.

> Any idea how I can track what's generating all those "[]" ?
> Note that the (,,) seems to be the NGramTag. data which is basically
> used as a list (Zipper).

For that, I recommend rebuilding with profiling and use the RTS flag -hc.

For more details on how to profile programs like this, check out:

    http://blog.ezyang.com/2011/06/pinpointing-space-leaks-in-big-programs/

Edward



------------------------------

Message: 2
Date: Mon, 5 Dec 2011 14:08:59 +0600
From: "Alexander.Vladislav.Popov "
        <alexander.vladislav.po...@gmail.com>
Subject: [Haskell-beginners] FFI export lazy list of string
To: beginners@haskell.org
Message-ID:
        <calpbq9aylhmu4yh2wuda9-ykxyhw25czcbcovon8hn+-oqu...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi, Haskellers.

Advise me please, how I can export lazy and potentially infinite list of
string from Haskell program. I think I must call it iteratively: the first
call initiate some structure and other calls iterate over it, something
like pair of function `find_first' and `find_next'. And how to marshall
this structure between programs. Or think in a wrong way? Does any example
exist how I can make it?

Alexander Popov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20111205/5ec9b77f/attachment-0001.htm>

------------------------------

Message: 3
Date: Mon, 5 Dec 2011 16:39:06 +0600
From: "Alexander.Vladislav.Popov "
        <alexander.vladislav.po...@gmail.com>
Subject: [Haskell-beginners] Compiling shared (dll) library
To: beginners@haskell.org
Message-ID:
        <CALpbQ9biEiK4am0UyZQpuOgrqiWfNd4PRmme+BDabj_hqYLx=a...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi, Haskellers.

I'm trying to compile following program (where Regex.Genex is a package
what I need to produce all possible expresions by the given pattern and
`adder' is just FFI sample):

-- genexlib.hs
{-# LANGUAGE BangPatterns, ForeignFunctionInterface #-}

module GenexLib where

import Regex.Genex
import System.IO
import System.Environment

adder :: Int -> Int -> IO Int  -- gratuitous use of IO
adder x y = return (x+y)
foreign export stdcall adder :: Int -> Int -> IO Int
-- genexlib.hs end

// start.c
#include <Rts.h>

void HsStart()
{
   int argc = 1;
   char* argv[] = {"ghcDll", NULL}; // argv must end with NULL

   // Initialize Haskell runtime
   char** args = argv;
   hs_init(&argc, &args);
}

void HsEnd()
{
   hs_exit();
}
// start.c end

I'm using ghc

>ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.0.2

compiling:
>ghc -c genexlib.hs
>ghc -c start.c
>ghc -shared -o genexlib.dll genexlib.o genexlib_stub.o start.o
genexlib.o:fake:(.text+0xd1): undefined reference to
`__stginit_regexzmgenexzm0zi3zi2_RegexziGenex_'
Creating library file: genexlib.dll.a
collect2: ld returned 1 exit status

and get undefined reference.

But If I try to compile the executable from similar code:

-- genexlib.hs
{-# LANGUAGE BangPatterns, ForeignFunctionInterface #-}

-- module GenexLib where

import Regex.Genex
import System.IO
import System.Environment

defaultRegex :: String
defaultRegex = "a(b|c)d{2,3}e*"

main :: IO ()
main = do
    hSetBuffering stdout NoBuffering
    args <- getArgs
    case args of
        [] -> do
            prog <- getProgName
            if prog == "<interactive>" then run [defaultRegex] else do
                fail $ "Usage: " ++ prog ++ " regex [regex...]"
        rx -> run rx

run :: [String] -> IO ()
run regex = do
  let s = genexPure regex
  mapM_ print s
-- genexlib.hs end

>ghc --make genexlib.hs -O2

it's ok, no errors, and you can see in GHCi:
*Main> :main
"abdd"
"acdd"
"abddd"
"acddd"
"abddeee"
"acddeee"
"abdddeee"
"acdddeee"
"abddee"
"acddee"
"abdddee"
"acdddee"
"abdde"
"acdde"
"abddde"
"acddde"

Where is my mistake? What am I doing wrong?
In first case, when compiling shared dll, I tried to link libraries what
I've found in `cabal' directory (like `libHSregex-genex-0.3.2.a') to work
around errors but all in vain.

--
Alexander Popov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20111205/322a160a/attachment-0001.htm>

------------------------------

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 42, Issue 5
****************************************

Reply via email to