Re: Foreign C with pointers

2007-12-19 Thread Lemmih
On Dec 19, 2007 3:05 AM, John Vogel [EMAIL PROTECTED] wrote:

 
 Lol, I am surprised that the library even compiled without the return
 addr;.

 But, this definition is correct:

Well, yeah, for some value of correct. It works in this case but it
will most likely bite you if you use it in any other way.

 The other 2 definitions don't even compile.

I posted two new type-signatures and two new definitions. I'm quite
sure the right combination would work.

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


Re: Foreign C with pointers

2007-12-18 Thread Lemmih
On Dec 19, 2007 1:06 AM, John Vogel [EMAIL PROTECTED] wrote:

 You do realize that the example you gave is just as general as all the
 tutorials.

 Here is an example I was working, but it gives a segmentation fault for some
 reason:

 example.h

  typedef struct
 {
  unsigned char a;
  unsigned char b;
  unsigned char c;
  unsigned char d;
 } IP;

 IP* shiftIP(IP* addr);


 example.c

 #include example.h

 IP* shiftIP(IP* addr){
  unsigned char t;
  t = addr-a;
  addr-a = addr-b;
  addr-b = addr-c;
  addr-c = addr-d;
  addr-d = t;
 }

return addr; ?
or rather, void shiftIP.

 Example.hsc

 {-# OPTIONS -ffi -fglasgow-exts #-}
 module Example where

 import Foreign
 import Foreign.C.Types
 import Control.Monad

 #include buzz.h

 data MyIP = MyIP
  { a :: CUChar
  , b :: CUChar
  , c :: CUChar
  , d :: CUChar
  } deriving (Show)

 instance Storable MyIP where
  sizeOf _ = #{size IP} -- 4
  alignment _ = alignment (undefined :: CUChar) -- 1
  peek p = return MyIP
`ap` (#{peek IP, a} p)
`ap` (#{peek IP, b} p)
`ap` (#{peek IP, c} p)
`ap` (#{peek IP, d} p)
  poke p ip = do
#{poke IP, a} p $ a ip
#{poke IP, b} p $ b ip
#{poke IP, c} p $ c ip
#{poke IP, d} p $ d ip

 foreign import ccall safe static buzzlib.h shiftIP
  shiftIP :: Ptr MyIP - Ptr MyIP

shiftIP isn't a pure function.

shiftIP :: Ptr MyIP - IO (Ptr MyIP) or
shiftIP :: Ptr MyIP - IO ()

 shiftMyIP :: MyIP - MyIP
 shiftMyIP ip = unsafePerformIO . alloca $ \ptr - poke ptr ip  peek
 (shiftIP ptr)

shiftMyIP ip = unsafePerformIO . alloca $ \ptr - poke ptr ip  peek
= (shiftIP ptr)  or
shiftMyIP ip = unsafePerformIO . alloca $ \ptr - poke ptr ip 
shiftIP ptr  peek ptr

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


Re: ghci changes in 6.8 that are not improvements

2007-11-30 Thread Lemmih
On Nov 30, 2007 12:36 PM, Simon Marlow [EMAIL PROTECTED] wrote:
 Alex Jacobson wrote:
 
  $ darcs get http://happs.org/HAppS-Begin
  $ cd HAppS-Begin
  $ curl http://searchpath.org/searchpath/SearchPath.hs  SearchPath.hs
  $ ghc --make SearchPath.hs -o sp
  $ sp ghci -ihaskell haskell/Main.hs
  Prelude :r
 

 I don't see any unnecessary reloading here:


 Ok, modules loaded: [snip].
 *Main :r
 Ok, modules loaded: [snip].

 Tried this on both x86_64/Linux (Fedora 6) and x86/Linux (RedHat 7).  Any
 idea what might be different about your setup?

It reloads all modules after an error has occurred.

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


Re: capabilities of GHC API

2007-05-19 Thread Lemmih

On 5/19/07, Frederik Eaton [EMAIL PROTECTED] wrote:

Hello,

I think what I'm trying to do is too ambitious, but I thought I would
ask to see if it is possible. It seems like there is no easy way to do
it, given what I've seen of the GHC API.

I would like to have a function, say it is called this, which has
the following effect in ghci

 let n = 2 in this
 n
2

In other words, it captures all the variables which are in scope, and
adds them to the GHCi environment. Somebody helpful will probably say
But you can just write 'let n = 2'!, but that is not the aim. There
are several aims. One is to be able to look at the variables inside a
function which one is trying to debug, then inserting 'this' will
cause them to be in scope, I think that would be useful. A more
important aim is to be able to use existentially quantified variables
easily. Currently I can do:

 reifyIntegral 5 (\n - print $ reflectNum n)
5

but how can I get GHCi to have an 'n' binding which is inside the
function? Clearly just returning 'n' will not work:

 reifyIntegral 5 id

interactive:1:0:
Inferred type is less polymorphic than expected
...

This is what I am thinking of doing, but as I said it seems ambitious.
There are several easier things one could think of:

 let n = 2 in bind n n
 n
2

If it were possible to add bindings to the GHCi bindings list, then
this would be easy. Is it possible? The documentation doesn't seem to
mention such a capability.

Also, probably another useful feature would be to combine 'this' with
something in the IO monad:

 withProgName blah thisIO
 getProgName
blah

So, are these things currently possible? Planned? Have the functions I
describe been implemented already? I think there is a GHCi debugger in
the works, so maybe functionality like this will be part of it, I
didn't want to start something on my own if that is the case...


This is pretty much that the GHCi debugger does expect it restores the
environment at the end of a breakpoint.

If you have GHC-6.6 or greater, try: let n = 2 in GHC.Base.breakpoint ()

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


Re: capabilities of GHC API

2007-05-19 Thread Lemmih

On 5/19/07, Frederik Eaton [EMAIL PROTECTED] wrote:

 This is pretty much that the GHCi debugger does expect it restores
 the
 environment at the end of a breakpoint.

I can't make any sense of what you wrote. Did you mean what instead
of that, and except instead of expect?


Ah, yes. I should really pay more attention.

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


Re: hrm...

2007-01-26 Thread Lemmih

On 1/27/07, John Meacham [EMAIL PROTECTED] wrote:

so I have this simple bit of code, which should be fast but seems to be
being compiled to something very slow.

 import Data.Word
 import Data.Bits

 fhb :: Word - Word
 fhb w = b1 .|. b2  where
 b2 = if 0x .. w /= 0 then 0x2 else 0
 b1 = if 0xFF00FF00 .. w /= 0 then 0x1 else 0

what it compiles to is something involving Integers, lots of coercions
and other nasty stuff when it should consist of a couple of primitive
operations.


Output from an AMD64 box:

$wfhb =
 \ (ww_sIw :: GHC.Prim.Word#) -
   case GHC.Prim.eqWord# (GHC.Prim.and# __word 4278255360 ww_sIw) __word 0
   of wild2_aHI {
 GHC.Base.False -
   case GHC.Prim.eqWord# (GHC.Prim.and# __word 4294901760 ww_sIw) __word 0
   of wild21_XHW {
 GHC.Base.False - __word 3; GHC.Base.True - __word 1
   };
 GHC.Base.True -
   case GHC.Prim.eqWord# (GHC.Prim.and# __word 4294901760 ww_sIw) __word 0
   of wild21_XHW {
 GHC.Base.False - __word 2; GHC.Base.True - __word 0
   }
   }


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


Re: OPTIONS_GHC -auto-all

2006-12-04 Thread Lemmih

On 12/4/06, Serge D. Mechveliani [EMAIL PROTECTED] wrote:

In my previous letter I wrote about

  {-# OPTIONS_GHC -fglasgow-ext -prof -auto-all #-}

in  ghc-6.6.

Now, I improve the typo and enter

  {-# OPTIONS_GHC -fglasgow-exts -prof -auto-all #-}

in order to force  -auto-all  for a certain particular module.
It still reports

  make build
  runhaskell Setup.hs build
  Preprocessing library dumatel-1.6...
  Building dumatel-1.6...
  LemmaSearch.hs:
  unknown flags in  {-# OPTIONS #-} pragma: -prof -auto-all

Who knows, please, what is the matter?


-prof and -auto-all are static flags. They cannot be turned on after
GHC starts processing the file.
See 
http://www.haskell.org/ghc/docs/latest/html/users_guide/static-dynamic-flags.html

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


Re: getting the -B topdir for a GHC-API app

2006-10-22 Thread Lemmih

On 10/22/06, Mathew Mills [EMAIL PROTECTED] wrote:

What is the right way to get the topDir for use with the GHC API.
I have a little app that I would like to cabalize and release, but I
am not sure what is the approved way of getting the '-B' option set-up.

I think it would be great if I could use template-haskell to insert
the topDir from the ghc used to compile the app, but I am not sure
how to get the topDir from the compiler.  Is this possible?


You can find the topDir by running: /path/to/ghc --print-libdir

This setup script does almost every thing you need:
http://www.cse.unsw.edu.au/~dons/code/hs-plugins/scripts/Setup-with-ghc.lhs

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


Re: foldl laziness support

2006-10-15 Thread Lemmih

On 10/15/06, Serge D. Mechveliani [EMAIL PROTECTED] wrote:

Dear Haskell implementors,

I keep on facing a frightening problem of the laziness support.
Consider the example of

---
import List (union)

main = let n = 10^4 :: Int
   in
   putStr
   (shows (take 2 $ unionMany [[1 .. i] | i - [1 .. n]]) \n)

unionMany = foldl union []
---

Compiling it in   ghc-6.6,  -O,

we have the running cost  O(n),  instead of  O(1).

Now, changing to

  unionMany []=  []
  unionMany (xs: xss) =  union xs (unionMany xss)
,
we reach  O(1).
For example, for  n = 10^9,  the time remains less than   0.01 sec.

My program has many fragments of such kind, when a function produces
a long list, some client functions need all the list, and others need
only its small initial part.
When we rely on the standard library,  foldl  creeps in everywhere.
Also may things are easy to program via  foldl.

I wonder how to avoid these numerous cost pitfalls.
Maybe, the complier could do more optimization?


How about using 'foldr'?

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


Re: Change Data.Bits.rotate to rotate Integer (unbounded) types

2006-09-19 Thread Lemmih

On 9/19/06, Peter Tanski [EMAIL PROTECTED] wrote:

I don't have a particular implementation in mind but as a general
idea it would make the treatment of Integers the same as the
treatment of the standard-size bounded ints.  A possible
implementation might be a stream cipher that uses 128-bit Integers
instead of 32-bit ints (bitwise rotations have been used in more than
a few stream ciphers).  For arithmetic purposes, rotation is also
useful for implementing multiplication of finite fields.


Ah, so you want to rotate various bounded integers larger than 64bits?
You can do that without changing Data.Bits at all (crypto defines
Word128, Word192 and Word256 which are instances of Bits).

--
Cheers,
 Lemmih

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


Re: [Haskell] STM applications and examples?

2006-06-15 Thread Lemmih

On 6/13/06, Simon Marlow [EMAIL PROTECTED] wrote:

Hi Folks,

I'm interested in gathering information about existing STM applications
and example code that people might be working on or have lying around.
It would be great to maintain a list of such applications and example
code on the wiki somewhere, and use it as a resource for learning STM
and research into STM implementations.

If you have an application using STM, please let us know.  If you can
supply the code, even better.  Similarly if you have some STM code that
might be suitable as samples or benchmarks, we'd love to collect it.


Conjure (a bittorrent client) is using STM quite heavily. It isn't
usable as a whole but it has some interesting parts.
Darcs repository: http://darcs.haskell.org/~lemmih/conjure/

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


Re: ghc api / calling functions?

2006-05-16 Thread Lemmih

On 5/16/06, Maarten [EMAIL PROTECTED] wrote:

Dear all,

Is there a way to use the ghc api to call functions directly instead of
evaluating statements (more or less similar to hs-plugins)?

So far, thanks to some info pages, I have been able to load sessions and
make modules, however there seems to be little or no documentation on
calling functions directly. Any info/pointers appreciated. Thanks.


Here's some code from hIDE:

compileSymbol :: Session - String - IO (HValue, Type)
compileSymbol session symbol
   = do name - fmap expectOneName (GHC.parseName session symbol)
Just tything - GHC.lookupName session name
let globalId = getGlobalId  tything
hscEnv - GHC.sessionHscEnv session
unlinked - coreExprToBCOs (hsc_dflags hscEnv) (Var globalId)
hvalue - linkExpr hscEnv unlinked
return (hvalue, idType globalId)
   where getGlobalId (AnId id) | isGlobalId id = id
 getGlobalId (AnId _) = error $ symbol ++ : not a global id
 getGlobalId (ADataCon _) = error $ symbol ++ : is a data constructor
 getGlobalId (ATyCon _) = error $ symbol ++ : is a type constructor
 getGlobalId (AClass _) = error $ symbol ++ : is a class
 expectOneName [x] = x
 expectOneName [] = error $ No such symbol in plugin:  ++ symbol
 expectOneName _ = error $ Ambiguous symbol in plugin:  ++ symbol

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


Re: ghc api / calling functions?

2006-05-16 Thread Lemmih

On 5/16/06, Maarten [EMAIL PROTECTED] wrote:

This seems to work fine. Thanks.

Couldn't find the source snippet in the hide sources online. I take it
the source is from the ghc port you are working on right now? Are the
sources available or do you need anybody to test? :)


The code is from here:
http://darcs.haskell.org/hIDE/packages/hidePlugin/src/Hide/Plugin/LoaderMidLevel.hs

There isn't much to test yet, unfortunately.

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


Re: eval in ghc(i)?

2006-05-05 Thread Lemmih

On 5/5/06, Geoffrey Alan Washburn [EMAIL PROTECTED] wrote:

Lemmih wrote:
 On 5/4/06, Donald Bruce Stewart [EMAIL PROTECTED] wrote:
 geoffw:
 
I have an application written in OCaml that I'm interested in
porting over to Haskell, and I was wondering what the best way
 to replace
  the following OCaml function would be:
 
  Toploop.initialize_toplevel_env();;
 
  let eval txt = let lb = (Lexing.from_string txt) in
   let phr = !Toploop.parse_toplevel_phrase lb in
   Toploop.execute_phrase true Format.std_formatter phr;;
 
  eval let add1 x = x +1
  eval add1 2
 
  Where I would like to be able to eval Haskell-code instead.  It looks
  like I might be able to achieve something like this using hs-plugins,
  but it looks a bit more complex.  Is hs-plugins the best choice for
 this
  kind of meta-programming?  I'm pretty sure Template Haskell will not
  work for me, at least as I understand it I can only manipulate program
  fragments that will be compiled later and as such that it will not be
  possible to execute them until the next phase.

 You can do some forms of runtime metaprogrammign with hs-plugins, yes.
 E.g.

 Prelude System.Eval.Haskell v - eval 1 + 2 :: Int [] :: IO (Maybe
 Int)
 Prelude System.Eval.Haskell v
 Just 3

 Prelude System.Eval.Haskell mf - eval \\x - x + 1 :: Int [] :: IO
 (Maybe (Int - Int))
 Prelude System.Eval.Haskell let f = fromJust mf
 Prelude System.Eval.Haskell :t f
 f :: Int - Int
 Prelude System.Eval.Haskell f 7
 8

 So if your program critically relies on this its possible to do.

 You can also use the GHC library:
 Prelude :m GHC
 Prelude GHC GHC.init (Just
 /home/david/coding/haskell/ghc/usr/lib/ghc-6.5)
 Prelude GHC session - newSession Interactive
 Prelude GHC setSessionDynFlags session = initPackages =
 getSessionDynFlags session
 Prelude GHC setContext session [] [mkModule Prelude]
 Prelude GHC runStmt session let add1 x = x + 1
 Prelude GHC runStmt session add1 2
 3
 Prelude GHC :q
 Leaving GHCi.

Thanks!  I think this is a bit closer to what I'm looking for than the
hs-plugins eval.  It is possible to get runStmt to output the result of
the session to a string rather than stdout?


Yeah:

Prelude GHC GHC.Exts Just n - compileExpr session show (add1 2)
Prelude GHC GHC.Exts let n' = unsafeCoerce# n :: String
Prelude GHC GHC.Exts n'
3

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


Re: eval in ghc(i)?

2006-05-03 Thread Lemmih

On 5/4/06, Donald Bruce Stewart [EMAIL PROTECTED] wrote:

geoffw:

   I have an application written in OCaml that I'm interested in
   porting over to Haskell, and I was wondering what the best way to 
replace
 the following OCaml function would be:

 Toploop.initialize_toplevel_env();;

 let eval txt = let lb = (Lexing.from_string txt) in
  let phr = !Toploop.parse_toplevel_phrase lb in
  Toploop.execute_phrase true Format.std_formatter phr;;

 eval let add1 x = x +1
 eval add1 2

 Where I would like to be able to eval Haskell-code instead.  It looks
 like I might be able to achieve something like this using hs-plugins,
 but it looks a bit more complex.  Is hs-plugins the best choice for this
 kind of meta-programming?  I'm pretty sure Template Haskell will not
 work for me, at least as I understand it I can only manipulate program
 fragments that will be compiled later and as such that it will not be
 possible to execute them until the next phase.

You can do some forms of runtime metaprogrammign with hs-plugins, yes.
E.g.

Prelude System.Eval.Haskell v - eval 1 + 2 :: Int [] :: IO (Maybe Int)
Prelude System.Eval.Haskell v
Just 3

Prelude System.Eval.Haskell mf - eval \\x - x + 1 :: Int [] :: IO (Maybe (Int 
- Int))
Prelude System.Eval.Haskell let f = fromJust mf
Prelude System.Eval.Haskell :t f
f :: Int - Int
Prelude System.Eval.Haskell f 7
8

So if your program critically relies on this its possible to do.


You can also use the GHC library:
Prelude :m GHC
Prelude GHC GHC.init (Just /home/david/coding/haskell/ghc/usr/lib/ghc-6.5)
Prelude GHC session - newSession Interactive
Prelude GHC setSessionDynFlags session = initPackages =
getSessionDynFlags session
Prelude GHC setContext session [] [mkModule Prelude]
Prelude GHC runStmt session let add1 x = x + 1
Prelude GHC runStmt session add1 2
3
Prelude GHC :q
Leaving GHCi.


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


Re: eval in ghc(i)?

2006-05-03 Thread Lemmih

On 5/4/06, wld [EMAIL PROTECTED] wrote:

Hi,

On 5/4/06, Lemmih [EMAIL PROTECTED] wrote:

 You can also use the GHC library:
 Prelude :m GHC
 Prelude GHC GHC.init (Just /home/david/coding/haskell/ghc/usr/lib/ghc-6.5)
 Prelude GHC session - newSession Interactive
 Prelude GHC setSessionDynFlags session = initPackages =
 getSessionDynFlags session
 Prelude GHC setContext session [] [mkModule Prelude]
 Prelude GHC runStmt session let add1 x = x + 1
 Prelude GHC runStmt session add1 2
 3
 Prelude GHC :q
 Leaving GHCi.

Please tell what options do you use to build ghc in to get
package ghc working? I get the following trying to load it:

$ ./ghc-inplace --interactive -package ghc
   ___ ___ _
  / _ \ /\  /\/ __(_)
  / /_\// /_/ / /  | |  GHC Interactive, version 6.5, for Haskell 98.
/ /_\\/ __  / /___| |  http://www.haskell.org/ghc/
\/\/ /_/\/|_|  Type :? for help.

Loading package base-1.0 ... linking ... done.
Loading package template-haskell-1.0 ... linking ... done.
Loading package readline-1.0 ... linking ... done.
Loading package unix-1.0 ... linking ... done.
Loading package Cabal-1.1.4 ... linking ... done.
Loading package haskell98-1.0 ... linking ... done.
Loading package ghc-6.5 ... ghc-6.5: can't load .so/.DLL for: HSghc
(libHSghc.so: cannot open shared object file: No such file or
directory)


Nothing, my patches for loading 'ghc' in ghci have resided in the main
repository for a couple of months.

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


Re: 'while' loop on mutable arrays causes stack overflow

2006-04-20 Thread Lemmih
On 4/20/06, Gunnar Kedenburg [EMAIL PROTECTED] wrote:
 Hello,

 a friend and I were recently experimenting with mutable arrays. We tried
 to implement a simple dot product on STUArrays using a 'while' loop.
 Unfortunately, every implementation we produced caused a stack overflow.
 Switching to other implementations of 'while' or to IOUArrays did not
 help us.

 We were using ghc-6.4.1 on Linux x86, with gcc 3.3.6. It runs perfectly,
 and is actually quite fast, when we increase the stack space. :)

  import Control.Monad.ST
  import Data.STRef
  import Data.Array.ST
  import Control.Monad.Fix
  import Control.Monad
 
  while :: STRef s Bool - ST s () - ST s ()
  while b c = readSTRef b = \v - when v (c  while b c)
 
  dot :: STUArray s Int Double - STUArray s Int Double - ST s Double
  dot x y = do
let (l,r) = bounds x
a - newSTRef 0.0
e - newSTRef l
b - newSTRef True
while b (do
   ev - readSTRef e
   av - readSTRef a
   xe - readArray x ev
   ye - readArray y ev
   writeSTRef b (evr)
   writeSTRef e (ev+1)
   writeSTRef a (av+xe*ye))
readSTRef a
 
  main = do
 let d = runST (do
  x - newArray (1, 100) 1.0
  y - newArray (1, 100) 2.0
  dot x y)
 putStrLn $ show d


Implementing 'dot' without the 'while' loop and STRefs will make it
shorter and faster, btw.

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


Re: inside the GHC code generator

2006-03-12 Thread Lemmih
On 2/24/06, Simon Peyton-Jones [EMAIL PROTECTED] wrote:
 | last days i studied GHC code generator, reading -ddumps of all sorts,
 | GHC sources, various papers and John's appeals :)
 |
 | what i carried from this investigation:
 |
 | GHC has great high-level optimization. moreover, GHC now allows to
 | program STG almost directly. when i look at STG code i don't see
 | anything that can be done better - at least for these simple loops i
 | tried to compile. i see just unboxed variables, primitive operations
 | and simple loops represented as tail recursion. fine.
 |
 | then STG compiled to the simplified C (called abstract C earlier and
 | quasi C-- now), what is next can be translated:
 |
 | * to real C and then compiled by gcc
 | * to assembler by build-in simple C-- compiler
 | * to assembler by some external C-- compiler (at least it is
 | theoretically possible)

 Good stuff Bulat.  There's plenty of interesting stuff to be done here.

 However, let me strongly urge you *not* to focus attention primarily on
 the gcc route.  Compiling via C has received a lot of attention over the
 years, and there are many papers describing cool hacks for doing so.
 GHC does not do as well as it could.

 But there are serious obstacles.  That's not gcc's fault -- it wasn't
 designed for this.  Accurate GC is one of them, tail calls is another,
 and there are plenty more smaller things that bite you only after you've
 invested a lot of time.  This way lies madness.

 C-- was *designed* for this purpose.  GHC uses C-- as its intermediate
 language (just before emitting C).  So a good route is this:

 * Write C-- to C-- optimisations

 * Then, if you like, translate that code to C.  Already you will be
 doing better than GHC does today, because the C-- to C-- optimiser will
 let you generate better C

 * But you can also emit C--, or native code; both of these paths will
 directly benefit from your C-- optimisations.

 The point is that none of this relies on Quick C--; you can always use
 an alternative back end.



 You can almost do this today. GHC uses C-- as an intermediate language.
 But alas, GHC's code generator does not take advantage of C--'s native
 calls or parameter passing.  Instead, it pushes things on an auxiliary
 stack etc.  (Those Sp memory operations you see.)  This isn't necessary.
 We are planning to split GHC's code generator into two parts
 A) Generate C-- with native calls, with an implicit C-- stack
 B) Perform CPS conversion, to eliminate all calls in favour of
 jumps
 using an explicit stack
 The current code gen is A followed by B.  But A is a much more suitable
 optimisation platform, and gives more flexibility.

 Chris Thompson, and undergrad at Cambridge, is doing (B) as his
 undergrad project, although it remains to be seen whether he'll have
 enough complete to be usable.

 Another shortcoming is that the native code generator in GHC isn't
 capable of dealing with backward jumps to labels (because GHC hasn't
 needed that so far).  But if you did C-- optimisation, you'd probably
 generate such jumps.  It'd be great to beef up the native code gen to
 handle that.


 Many of the optimisations you describe (perhaps all) are readily
 expressible in the C-- intermediate language, and by working at that
 level you will be independent of with the back end is gcc, a native code
 generator, or Quick C--, or some other C-- compiler.  Much better.

What optimizations are we talking about here? The loop optimizations
that Bulat implicitly proposed would only affect recursion over
unboxed arguments, and, since that's fairly rare, wouldn't give Joe
Hacker any noticeable speed up.
Are we at the end of what we can get without whole-program
optimizations or are there other optimizations that apply to C--
representing a lazy PL?

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


Re: Missing Folder in ghc?

2006-02-28 Thread Lemmih
On 2/28/06, Ashley Yakeley [EMAIL PROTECTED] wrote:
 I'm trying to build GHC from source. But the ghc repository at
 http://darcs.haskell.org/ghc seems to be missing ghc/lib/compat/Cabal?

Did you run 'sh darcs-all get'?

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


Re: Re[2]: inside the GHC code generator

2006-02-24 Thread Lemmih
On 2/24/06, Bulat Ziganshin [EMAIL PROTECTED] wrote:
 Hello kyra,

 Friday, February 24, 2006, 12:37:02 AM, you wrote:

  i prefer to see the asm code. this may be because of better high-level
  optimization strategies (reusing fib values). the scheme about i say
  will combine advantages of both worlds
 k no strategies, plain exponential algorithm,

 yes, the ocaml compiler works better with stack. but i sure that in
 most cases gcc will outperform ocaml because it has large number of
 optimizations which is not easy to implement (unrolling, instruction
 scheduling and so on)

 k also, Clean is *EXACTLY* in line with ocaml. This is interesting,
 k because Clean is so much similar to Haskell.

 clean differs from Haskell in support of unique types and strictness
 annotations. the last is slowly migrates into GHC in form of shebang
 patters, but i think that it is a half-solution. i mentioned in
 original letter my proposals to add strictness annotations to
 function types declarations and to declare strict datastructures, such
 as ![Int]

As I've understood it, Clean's strictness annotations are a bit of a
hack which only works on certain built-in types. Am I mistaking here?

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


Re: Re[4]: inside the GHC code generator

2006-02-24 Thread Lemmih
On 2/24/06, Bulat Ziganshin [EMAIL PROTECTED] wrote:
 Hello Lemmih,

 Friday, February 24, 2006, 1:15:51 PM, you wrote:

  clean differs from Haskell in support of unique types and strictness
  annotations. the last is slowly migrates into GHC in form of shebang
  patters, but i think that it is a half-solution. i mentioned in
  original letter my proposals to add strictness annotations to
  function types declarations and to declare strict datastructures, such
  as ![Int]

 L As I've understood it, Clean's strictness annotations are a bit of a
 L hack which only works on certain built-in types. Am I mistaking here?

 i don't know Clean very well, although i've seen rumors that it
 supports strict datastructures. after all, this don't need changes in
 language itself, it's just a syntax sugar:

 data [a] = [] | a:[a]
 x :: ![Int]

 translates to the

 data StrictList a = Nil | Cons a !(StrictList a)
 x :: !(StrictList a)

Let's try this:

x :: ![Int] - Int

It would translate to something like this:

mkStrictList :: [a] - StrictList a
x = xStrict . mkStrictList
xStrict = ...

Wouldn't it be very expensive to strictify the list?

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


Re: New bug tracker: Trac

2006-01-22 Thread Lemmih
On 12/6/05, Simon Marlow [EMAIL PROTECTED] wrote:
 Developers with an account on cvs.haskell.org: please add yourselves as
 users on the Trac, so I can give out permissions to edit tickets.  You
 create a user like this:

   - log in to cvs.haskell.org
   - htpasswd /srv/trac/ghc/trac.htpasswd username
   - type your password when prompted
   - let me know when you've done this

Done.

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


Re: Error in GHC

2006-01-18 Thread Lemmih
On 1/18/06, Tays Soares [EMAIL PROTECTED] wrote:
  I'm trying to run the following sequence on ghc 6.4:
   ghc -fglasgow-exts --make Main

  ghc -o exec Main.o Exemplo1.o

 But I always get this error message after the second command:
 /usr/lib/ghc-6.4/libHSrts.a(Main.o)(.text+0xe): In function `main':
 : undefined reference to `__stginit_ZCMain'
 /usr/lib/ghc-6.4/libHSrts.a(Main.o)(.text+0x28): In function `main':
 : undefined reference to `ZCMain_main_closure'
 collect2: ld returned 1 exit status

 Please, does anybody know what can I do to fix it?

Does your main module contain a function called main? Does ghc
-fglasgow-exts --make Main -o exec work?

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


GHC wish list.

2005-12-13 Thread Lemmih
Hiya,

I've been using the GHC library in hIDE and HASP for some time now and
there are a few things I'd love to see implemented:

  * Changeable lexer/parser (just like DynFlags.log_action)
  Not very important but it would be convenient in HASP.
  * Cabalization of the library.
  Not having a profiling version of the library and not being able to
rebuild it easily is a bit limiting.
  * GHCi compatibility.
  hIDE is currently using ghc-api[1] because the real library exports
symbols that clashes with GHCi.

--
Friendly,
  Lemmih

[1] ghc-api: http://scannedinavian.com/~lemmih/ghc-api
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: making with profiling, 6.4.1, cabal-1.1.3

2005-10-03 Thread Lemmih
On 10/3/05, Serge D. Mechveliani [EMAIL PROTECTED] wrote:
 People,

 I need help on making for profiling,
 and cannot decide whether the question is on GHC or on Cabal.

 I have  ghc-6.4.1,  and  Cabal-1.1.3-September-12
 installed in my user directory, under Debian Linux,
 and need to make a project for profiling.

 ghci -package Cabal
 says
  ...
  Loading package base-1.0 ... linking ... done.
  ...
  Loading package Cabal-1.1.3 ... linking ... done.


 I start with a contrived example project of  M1.hs, M2.hs, Main.hs:

 ---
 module M1 where  m1 = True

 module M2 where  import M1;  m2 = m1  m1

 Main.hs:  import M2l;main = putStr $ shows m2 \n
 ---

 For this,  ghc --make -prof -auto-all Main

 works as needed -- without packages.
 Now, try to make a package for profiling:

 foo.cabal:
   name:foo
   version: 1.0
   build-depends:   base, haskell98, data
   exposed-modules: M2
   other-modules:   M1
   ghc-options: -prof -auto-all -hisuf p_hi -osuf p_o

 The aim is to build  foo  (of M2)  as a library, then to make Main
 under the package  foo,  and with profiling.

 Then,  runhaskell Setup configure --ghc --prefix=$source/inst
runhaskell Setup build

 produces a report

 ---
 ...
 configure: Using compiler: /home/mechvel/ghc/6.4.1/inst/bin/ghc
 configure: Compiler flavor: GHC
 configure: Compiler version: 6.4.1
 configure: Using package tool: /home/mechvel/ghc/6.4.1/inst/bin/ghc-pkg
 configure: No haddock found
 configure: Using happy: /usr/bin/happy
 configure: Using alex: /usr/bin/alex
 configure: Using hsc2hs: /home/mechvel/ghc/6.4.1/inst/bin/hsc2hs
 configure: No c2hs found
 configure: No cpphs found
 configure: No greencard found
 configure: Dependency base-any: using base-1.0
 configure: Dependency haskell98-any: using haskell98-1.0
 configure: Dependency data-any: using data-1.0

 scico:~/t make build

 runhaskell Setup.hs build
 Preprocessing library foo-1.0...
 Building foo-1.0...
 Chasing modules from: M2,M1
 Skipping  M1   ( M1.hs, dist/build/M1.p_o )
 Skipping  M2   ( M2.hs, dist/build/M2.p_o )
 /usr/bin/ar: creating dist/build/libHSfoo-1.0.a
 /usr/bin/ar: dist/build/M2.o: No such file or directory
 make: *** [build] Error 1
 ---

 The directory   ~/t/dist/build   contains at this moment

   M1.p_hi  M1.p_o  M2.p_hi  M2.p_o  Main.p_hi  Main.p_o

 , and indeed, no  M2.o  file.

 If I remove  -hisuf p_hi -osuf p_o

 (by the way, why should the user think of these wise suffixes,
 maybe,  -prof  should be sufficient?
 ),
 then it reports  ...
  /usr/bin/ld: cannot find -lHSfoo-1.0_p
  collect2: ld returned 1 exit status

 What I am missing, please?
 Thank you in advance for the help.

You don't have to mess with GHC-Options at all. Just pass
--enable-library-profiling to the setup script when you're configuring
the library.

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


Re: ghc and cabal

2005-08-06 Thread Lemmih
On 8/6/05, Serge D. Mechveliani [EMAIL PROTECTED] wrote:
 On Aug 05, 2005 we  wrote:

  Serge D. Mechveliani [EMAIL PROTECTED] writes:
 
   Which Cabal version will be in official  ghc-6.4.1  by default?
 

  It'll be 1.0 with some bug fixes (Simon: can you please make the
  version number '1.0.1'?)
 

   If it is 1.0, then  ghc-6.4.1 will fail with `make' for profiling.
   So, the user needs to install another Cabal version and to link it
   to GHC, and this occurs difficult. This is likely to complicate the
   usage of GHC
 
  Yep.  Profiling support won't be there, but some of the problems you
  faced in building a separate Cabal will hopefully be fixed in the new
  version of GHC.


 First, I tried to test profiling in  ghc-6.4.1-pre-release,
 and could not -- due to this misfeature with _p modules in
 Cabal-1.0.
 Generally, what I need:
   fresh GHC with working profiling, with Cabal processing
   _p module suffixes, and such
   (in  runhaskell Setup build, install).

 If official  ghc-6.4.1 (with default Cabal version)  has not the
 needed feature, then, the next question is

   which higher Cabal version supports such `make' for profiling?

 After I know the answer to this, I could start searching for possible
 _simple instructions_  for the users of GHC and its applications on
 how to upgrade Cabal in their installed  ghc-6.4.1.  Such instructions
 that are clear almost to everyone, not only to system hackers.

 If all this occurs difficult to arrange, then the profiling occurs
 delayed to future official GHC versions.

(If I've completely misunderstood the question please ignore me :)
Guide to profiling in Cabal:

Step 1: Installing a new Cabal
You can either download Cabal 1.1.1 from the webpage or pull it from
http://cvs.haskell.org/darcs/cabal with darcs.
When you got the source tree you install it as any other Cabal package.
[global installation]
$ runhaskell Setup.lhs configure
$ runhaskell Setup.lhs build
$ sudo runhaskell Setup.lhs install

[user installation, GHC = 6.4 wont like this]
$ runhaskell Setup.lhs configure --prefix=/your/desired/prefix
$ runhaskell Setup.lhs build
$ runhaskell Setup.lhs install --user

Step 2: Compiling Cabal packages with profiling.
You can now pass '-p' or '--enable-library-profiling' when you
configure a package and the .cabal file will have a new stanza call
GHC-prof-options for profiling options.

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


Re: problems building trhsx-0.2 with ghc-6.5.20050723

2005-08-01 Thread Lemmih
On 8/1/05, Konovalov, Vadim [EMAIL PROTECTED] wrote:
 I built and installed ghc-6.5.20050723 on Linux from sources successfully,
 and it looks quite normally-working.
 
 I've stepped into a problem building trhsx from a package
 haskell-src-exts-0.2.tar.gz with a quite unexpected (for me) message:
 
 Preprocessing executables for trhsx-0.2...
 Building trhsx-0.2...
 hsSourceDirs: [.]
 Chasing modules from: Hsx.hs
 
 Hsx.hs:6:7:
 Could not find module `Data.List':
   it is a member of package base-1.0, which is hidden
 
 Lines in error is quite innocent-looking:
 import Data.List (intersperse, isPrefixOf)
 
 GHC version 6.4 builds that module okay.
 
 Is that error is due to beta version of ghc-6.5.20050723, or I am
 misunderstanding some configuration issues?

Cabal hides all packages when using GHC 6.5. Add 'base' to
build-depends in trhsx's cabal file and send a patch to the author.

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


Re: IO and STM

2005-04-13 Thread Lemmih
On 4/13/05, Robert van Herk [EMAIL PROTECTED] wrote:
 Hi all,
 
 I have a question about IO in a STM transaction.
 
 I want to make an atomic algorithm that does the following:
 
 1. read an IORef
 2. write some changes to the value you get from 1
 3. save the IORef again
 
 Currently, I did this, roughly like this:
 
 doSomething :: IORef [s] - s - IO ()
 doSomething ref s =
   atomically (
 do { ss - unsafeIOToSTM (readIORef s);
  do something with ss;
  unsafeIOToSTM (writeIORef s ss);
  return ()
}
   )
 
 Since I read that STM uses a revertable log, I was wondering what
 happens with the IO actions, when a rerun on the atomic part is
 performed... I guess it will just redo them? Is this the unsafe-part of
 unsafeIOToSTM, or are there more caveats?

You probably wanna use TVars instead of IORefs.
I would suggest reading the STM paper at
research.microsoft.com/~simonpj/papers/stm/stm.ps, if you haven't
already.

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


Re: [Haskell-cafe] Parse error

2005-03-17 Thread Lemmih
On Thu, 17 Mar 2005 20:42:30 +0100, Dmitri Pissarenko
[EMAIL PROTECTED] wrote:
 Hello!
 
 In the attachment you will find a file, in which I try to access Java from
 Haskell using the Java bridge for functional languages.
 
 For details see
 
 http://sourceforge.net/projects/jvm-bridge/
 
 and
 
 http://dapissarenko.com/resources/2005_02_17_eigenvaluesJava/2005_02_17_eigenva
 luesJava.pdf
 
 When I try to compile the attached file using
 
 ghc +RTS -c -RTS -package javavm  -c EigenvalueCalculatorHaskell.hs -o
 EigenvalueCalculatorHaskell.o
 
 I get the error
 
 EigenvalueCalculatorHaskell.hs:28: parse error on input `putStrLn'
 
 Unfortunately, I have not the slightest idea about how to fix/isolate it (I
 already commented out almost the whole code).
 
 Please tell me what I could try to correct the error. I appreciate ANY hint.

Use 'do {let {foo = baz}; bar }'. And Haskell code look _a lot_
prettier when using the layout to structure the program.

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


TH libraries and linking.

2005-03-14 Thread Lemmih
Greetings,

I've recently been playing around with using TH to generate FFI
bindings. The resulting code is in general very concise, more
maintainable and far less error-prone than the hand-written
counterpart. But increased code bloat ascends out of all this
happiness. The binding is required to link with both template-haskell
and the library which generates the FFI code, so any binary using the
generated binding would get a few hundred kilobytes added which
strictly aren't necessary (am I wrong here?). This can be unacceptable
for small bindings.
One could perhaps get around this cheap by changing the TH pretty
printer to output valid Haskell instead of just pretty Haskell (I'm
specifically talking about a misplaced 'where' in instance
declarations). Then one could use the TH library just like a normal
preprocessor.

I'm no expert so there's probably difficulties which I can't see.

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


GHCi and C++.

2005-02-25 Thread Lemmih
Greetings fellow Haskellers and other readers,

During my ongoing research on doing whatever I feel like, I
discovered that using C++ libaries in GHCi (no problems with GHC)
wasn't as pleasant as I had hoped.
Apparently C++ sources requires to be linked with crtbegin.o and
crtend.o (and others?) and I was wondering how to solve this nicely.
Any hints or pointers would be greatly appreciated.

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


Re: GHCi and C++.

2005-02-25 Thread Lemmih
On Fri, 25 Feb 2005 18:27:03 +, Duncan Coutts
[EMAIL PROTECTED] wrote:
 On Fri, 2005-02-25 at 19:05 +0100, Lemmih wrote:
  Greetings fellow Haskellers and other readers,
 
  During my ongoing research on doing whatever I feel like, I
  discovered that using C++ libaries in GHCi (no problems with GHC)
  wasn't as pleasant as I had hoped.
  Apparently C++ sources requires to be linked with crtbegin.o and
  crtend.o (and others?) and I was wondering how to solve this nicely.
  Any hints or pointers would be greatly appreciated.
 
 How about creating a dummy ghc package that has no Haskell code but
 specifies all the nasty link time options. i.e. using the
 extra_libraries, extra_ghc_opts, extra_cc_opts and extra_ld_opts fields.
 
 Then when compiling your program you just use -package c++ or (-package
 cpp or cpp-support if c++ is not a valid package name). if you
 make packages that depend on C++ support it's still easy, just make the
 new package depend on the cpp package.

Thanks for replying and it all sounds nice, but I'm not sure which
linker options I'm missing since the location of the crt*.o files
appears to be implementation specific.

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


Re: GHCi and C++.

2005-02-25 Thread Lemmih
On Fri, 25 Feb 2005 13:58:52 -0500, Wolfgang Thaller
[EMAIL PROTECTED] wrote:
  During my ongoing research on doing whatever I feel like, I
  discovered that using C++ libaries in GHCi (no problems with GHC)
  wasn't as pleasant as I had hoped.
  Apparently C++ sources requires to be linked with crtbegin.o and
  crtend.o (and others?) and I was wondering how to solve this nicely.
  Any hints or pointers would be greatly appreciated.
 
 I think the files crtbegin.o and crtend.o are Linux-specific or maybe
 GNU-binutils-specific. Different platforms tend to have different
 strange requirements for C++ code.
 
 Loading shared libraries that happen to be written in C++ into GHCi
 shouldn't be a problem (or is it? definitely works on Mac OS X).
 Loading C++ .o files is a different story.
 
 Generally speaking, there are at least two things that set C++ .o files
 apart from normal C .o files:
 
 *) static constructors/destructors
 
 Sometimes there are pieces of code that expect to be called before
 main() or at program termination. The GHCi Linker doesn't support this,
 so some code may crash because things haven't been initialised
 properly.
 
 *) multiple definitions
 
 There is often some code in C++ header files (e.g. templates, inline
 functions, class members declared in the class declaration). These
 pieces of code are sometimes inlined, but sometimes they are not; in
 that case, gcc generates code for them in every .o file that uses them
 and counts on the linker to just include one version in the final
 executable. The GHCi linker will probably just abort and complain about
 multiply-defined symbols.
 
 The above is just theory, there might be even more problems in practice
 :-( .

I've written a binding to a C++ library where I use a simple wrapper
file to overcome the name mangling (extern C functions calling C++,
nothing fancy). Is there a way to make that more GHCi friendly or
should I explore other options?

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


Re: Timing Functions

2005-01-17 Thread Lemmih
On Mon, 17 Jan 2005 10:48:18 -0600, jekwtw [EMAIL PROTECTED] wrote:
  
 I'm putting together a script to gather run-time stats for some functions
 I'm working with, and I'm having a terrible time.  My strategy is to
 evaluate a function a number of times and compute the difference between the
 elapsed CPU time before and after the repeated calls. 
 
  timeNReps :: (a - b) - a - Int - FilePath - IO ()
  timeNReps func arg reps fileName =
  do t0 - System.CPUTime.getCPUTime
   runNReps func arg reps
   t1 - System.CPUTime.getCPUTime
   appendFile fileName ((showMS (t1 - t0)) ++ \n)
 where
 showMS n = show (n `quot` 10)
 
 showMS just converts the pico-second result into milli-seconds and
 stringifies it.
 
 runNReps is an IO program (do sequence) that is intended to call the
 function and tail-call itself a given number of times: 
   
  runNReps :: (Int - a) - Int - Int - IO ()
  runNReps f x todo
  | todo  0 = do let junk = (f x)
 runNReps f x (todo - 1)
  | otherwise = return (())

Haskell is a non-strict language which means that 'junk' wont be
evaluated since it's not necessary for the function to terminate.
Check 'replicateM_' from Control.Monad.
 runNReps :: Int - IO a - IO ()
 runNReps = replicateM_

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


Re: HaXml and ghc-current

2005-01-11 Thread Lemmih
On 11 Jan 2005 01:07:38 +0100, Peter Simons [EMAIL PROTECTED] wrote:
 I see, thanks for the info! Any advice on how to
 build/install it with Cabal? I've tried it, but when Cabal
 tries to create the library, it appears to get the file
 suffixes wrong:
 
  $ runghc Setup.lhs Setup.lhs build
  | Preprocessing HaXml-1.0...
  | Building HaXml-1.0...
  | [...]
  | /usr/bin/ar: creating dist/build/libHSHaXml-1.0.a
  | /usr/bin/ar: 
 'dist/build/src/Text/ParserCombinators/HuttonMeijerWallace..o': No such file
  | /usr/bin/ar: 'dist/build/src/Text/XML/HaXml..o': No such file
  | /usr/bin/ar: 'dist/build/src/Text/XML/HaXml/Combinators..o': No such file
  | /usr/bin/ar: 'dist/build/src/Text/XML/HaXml/DtdToHaskell/Convert..o': No 
 such file
  | /usr/bin/ar: 'dist/build/src/Text/XML/HaXml/DtdToHaskell/Instance..o': No 
 such file
  | /usr/bin/ar: 'dist/build/src/Text/XML/HaXml/DtdToHaskell/TypeDef..o': No 
 such file
  | /usr/bin/ar: 'dist/build/src/Text/XML/HaXml/Escape..o': No such file
  | /usr/bin/ar: 'dist/build/src/Text/XML/HaXml/Haskell2Xml..o': No such file
  | /usr/bin/ar: 'dist/build/src/Text/XML/HaXml/Html/Generate..o': No such file
  | /usr/bin/ar: 'dist/build/src/Text/XML/HaXml/Html/Parse..o': No such file
  | /usr/bin/ar: 'dist/build/src/Text/XML/HaXml/Html/Pretty..o': No such file
  | /usr/bin/ar: 'dist/build/src/Text/XML/HaXml/Lex..o': No such file
  | /usr/bin/ar: 'dist/build/src/Text/XML/HaXml/OneOfN..o': No such file
  | /usr/bin/ar: 'dist/build/src/Text/XML/HaXml/Parse..o': No such file
  | /usr/bin/ar: 'dist/build/src/Text/XML/HaXml/Pretty..o': No such file
  | /usr/bin/ar: 'dist/build/src/Text/XML/HaXml/Types..o': No such file
  | /usr/bin/ar: 'dist/build/src/Text/XML/HaXml/Validate..o': No such file
  | /usr/bin/ar: 'dist/build/src/Text/XML/HaXml/Verbatim..o': No such file
  | /usr/bin/ar: 'dist/build/src/Text/XML/HaXml/Wrappers..o': No such file
  | /usr/bin/ar: 'dist/build/src/Text/XML/HaXml/Xml2Haskell..o': No such file
  | /usr/bin/ar: 'dist/build/src/Text/XML/HaXml/Xtract/Combinators..o': No 
 such file
  | /usr/bin/ar: 'dist/build/src/Text/XML/HaXml/Xtract/Lex..o': No such file
  | /usr/bin/ar: 'dist/build/src/Text/XML/HaXml/Xtract/Parse..o': No such file
  | /usr/local/ghc-current/bin/ghc -odir dist/build/src/tools -hidir 
 dist/build/src/tools -o dist/build/src/tools/Canonicalise --make -isrc/tools 
 src/tools/Canonicalise.hs
  | Chasing modules from: src/tools/Canonicalise.hs
  | src/tools/Canonicalise.hs:
  | Could not find interface file for `Text.XML.HaXml.Wrappers'
  | (use -v to see a list of the files searched for)
 
 Peter

Hmm yes. You should probably talk to Malcolm Wallace about it. I
haven't installed HaXml from CVS because I cabalized it on my own
before realizing others had already done it.

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


Re: HaXml and ghc-current

2005-01-10 Thread Lemmih
Hello Peter.

GHC can now handle Cabal packages (and only Cabal packages). But no
worries; HaXml is cabalized and should be available in your CVS source
tree.

On 10 Jan 2005 23:26:05 +0100, Peter Simons [EMAIL PROTECTED] wrote:
 Hi,
 
 I've just tried to install HaXml with the latest GHC from
 CVS, and the package compiles fine but the installation
 procedure aborts with:
 
   ghc-pkg: cannot find package HaXml
   `cat ghcpkgcmd` --add-package pkg.conf
   Reading package info from stdin...
 ghc-pkg: Line 1: Invalid syntax (no colon after field name)
 
 Apparently something has changed in the package database
 format? I haven't been following all this, so I am a bit at
 a loss what to do.
 
 Has anyone else managed to install HaXml successfully? Any
 advice?
 
 Peter
 

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