Re: [Haskell-cafe] Short Cut / Rewrite Rules Problem in GHC

2005-10-03 Thread Roberto Zunino

(moved to glasgow-haskell-users, hoping it's more appropriate)

Chris wrote:

Hi All. I am a student and a noob to Haskell. I am having some  
trouble with an example from the paper "Playing by the rules:  
Rewriting as a practical optimisation technique in GHC" by Simon  
Peyton Jones, Andrew Tolmach and Tony Hoare, specifically, the Short- 
cut Deforestation example in section 3.1. I was trying to compile the  
following using GHC version 6.4 on Mac OS X 10.4. The definition for  
build and the rule are from the paper (the rule also appears in the  
GHC online doc in section 7.10.1). 


[snip]


 build :: (forall b. (a->b->b) -> b -> b) -> [a]
 build' g = g (:) []


(Unrelated: there is an extra ' above)


 {-# RULES
 "foldr/build"
   forall k z (g::forall b. (a->b->b) -> b -> b) .
   foldr k z (build g) = g k z
 #-}


Beware of "#" at the beginning of line!
Try putting a space before the #.

My wild guess of what is causing the lexer error: as C compilers, GHC 
seems to read


# 12345 "foo"

as meaning "pretend that this is line 12345 in file foo". This is 
commonly used by automatic code generators (e.g. yacc) to force the 
compiler to emit error messages pointing to the human-written source 
(the file passed to yacc) and not to the generated code. This happens 
only if the # is the first character of the line.


( I do not dare to suggest modifying ghc/compiler/parser/Lexer.x as in
===

 {
 \n ;
 "#-}"{ token ITclose_prag }
 ^\# (line)?{ begin line_prag1 }

===
... so I'm _not_ suggesting it! ;-) )

Regards,
Roberto Zunino.
___
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


making with profiling, 6.4.1, cabal-1.1.3

2005-10-03 Thread Serge D. Mechveliani
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.

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