Send Beginners mailing list submissions to
        [email protected]

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
        [email protected]

You can reach the person managing the list at
        [email protected]

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


Today's Topics:

   1.  Logging in Haskell (Sergey Mikhanov)
   2. Re:  Logging in Haskell (Brent Yorgey)
   3.  What is the Haskell idiom for "if then else if   then"
      (Peter Hickman)
   4. Re:  What is the Haskell idiom for "if then else  if then"
      (Daniel Fischer)
   5.  can run in ghci but can't compile. (Anand Mitra)
   6. Re:  can run in ghci but can't compile. (Brandon S. Allbery KF8NH)
   7. Re:  can run in ghci but can't compile. (Anand Mitra)


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

Message: 1
Date: Mon, 30 Mar 2009 14:01:55 +0200
From: Sergey Mikhanov <[email protected]>
Subject: [Haskell-beginners] Logging in Haskell
To: "[email protected]" <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain;       charset=us-ascii;       format=flowed;  
delsp=yes

    Hi community,

As my Haskell programs grow above 100 lines of code, I feel the  
necessity to trace the execution of them more closely. In imperative  
languages one may use logging facilities for checking intermediary  
values of variables, the execution flow, etc. How this usually handled  
in Haskell (I bet that despite the fact that in Haskell it is  
relatively easier to write bug-free and checked code, the industrial  
systems still need some logging being done)?

Regards,
Sergey


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

Message: 2
Date: Mon, 30 Mar 2009 08:52:19 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Logging in Haskell
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Mon, Mar 30, 2009 at 02:01:55PM +0200, Sergey Mikhanov wrote:
>    Hi community,
>
> As my Haskell programs grow above 100 lines of code, I feel the necessity 
> to trace the execution of them more closely. In imperative languages one 
> may use logging facilities for checking intermediary values of variables, 
> the execution flow, etc. How this usually handled in Haskell (I bet that 
> despite the fact that in Haskell it is relatively easier to write bug-free 
> and checked code, the industrial systems still need some logging being 
> done)?

It depends what you want to do.  If you just want to print out some
intermediate values to do a little debugging, try the 'trace' function
from Debug.Trace.  If you actually want an industrial-strength logging
system, there's the hslogger library:

  http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hslogger

Generally collecting some information while a computation progresses
can be done with the Writer monad, from Control.Monad.Writer.

-Brent


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

Message: 3
Date: Mon, 30 Mar 2009 16:33:02 +0100
From: Peter Hickman <[email protected]>
Subject: [Haskell-beginners] What is the Haskell idiom for "if then
        else if then"
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes

I've just written this piece of code

     if r < 0
     then LEFT
     else
         if r > 0
         then RIGHT
         else STRAIGHT

which works just fine but it does look rather clunky (as it would in  
any language I suppose). Is there a Haskell idiom for this type of code?



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

Message: 4
Date: Mon, 30 Mar 2009 17:50:20 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] What is the Haskell idiom for "if
        then else       if then"
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="iso-8859-1"

Am Montag 30 März 2009 17:33:02 schrieb Peter Hickman:
> I've just written this piece of code
>
>      if r < 0
>      then LEFT
>      else
>          if r > 0
>          then RIGHT
>          else STRAIGHT
>
> which works just fine but it does look rather clunky (as it would in
> any language I suppose). Is there a Haskell idiom for this type of code?

Usually, people use guards:

function r
    | r < 0     = LEFT
    | r > 0     = RIGHT
    | otherwise = STRAIGHT

Another option would be a case:

    case compare r 0 of
      LT -> LEFT
      GT -> RIGHT
      EQ -> STRAIGHT

You can also have a case with guards:

case expression of
    pattern1 | condition1.1 -> result1.1
             | condition1.2 -> result1.2
    pattern2 | condition2.1 -> result2.1
    pattern3 -> result3
    _ -> defaultresult


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

Message: 5
Date: Mon, 30 Mar 2009 22:42:21 +0530
From: Anand Mitra <[email protected]>
Subject: [Haskell-beginners] can run in ghci but can't compile.
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Hi,

I can run the following program in the interpreter ghci but can't compile
it.

The program I am trying to compile is a simple copy using the lazy
bytestrings. I have been working out exercises from Real World haskell and I
was benchmarking this version which is supposed to be optimum.

,----
| import qualified  System  as S
| import qualified Data.ByteString.Lazy as L
|
| main = do
|   [from, to ] <- S.getArgs
|   file <- L.readFile from
|   L.writeFile to file
`----

While trying to compile this i get the following errors.

,----
| mi...@ravan:~/laptop/haskell/learn$ /opt/ghc-6.10.1/bin/ghc cp.hs
| cp.o: In function `sB1_info':
| (.text+0xab): undefined reference to
`bytestringzm0zi9zi1zi4_DataziByteStringziLazzy_writeFile_closure'
| cp.o: In function `sAW_info':
| (.text+0xe1): undefined reference to
`bytestringzm0zi9zi1zi4_DataziByteStringziLazzy_readFile_closure'
| cp.o: In function `sB5_info':
| (.text+0x30f): undefined reference to
`__stginit_bytestringzm0zi9zi1zi4_DataziByteStringziLazzy_'
| cp.o: In function `sB5_srt':
| (.data+0x4): undefined reference to
`bytestringzm0zi9zi1zi4_DataziByteStringziLazzy_readFile_closure'
| cp.o: In function `sB5_srt':
| (.data+0x8): undefined reference to
`bytestringzm0zi9zi1zi4_DataziByteStringziLazzy_writeFile_closure'
| collect2: ld returned 1 exit status
| mi...@ravan:~/laptop/haskell/learn$  rm cp.o
| mi...@ravan:~/laptop/haskell/learn$ /opt/ghc-6.10.1/bin/ghc cp.hs
| cp.o: In function `sB0_info':
| (.text+0xab): undefined reference to
`bytestringzm0zi9zi1zi4_DataziByteStringziLazzy_writeFile_closure'
| cp.o: In function `sAV_info':
`----

But this program is not syntactically or otherwise flawed since I can run it
under ghci.

,----
| mi...@ravan:~/laptop/haskell/learn$ /opt/ghc-6.10.1/bin/ghci
| GHCi, version 6.10.1: http://www.haskell.org/ghc/  :? for help
| Loading package ghc-prim ... linking ... done.
| Loading package integer ... linking ... done.
| Loading package base ... linking ... done.
| Prelude> :l cp.hs
| Ok, modules loaded: Main.
| Prelude Main> :main /etc/passwd /tmp/xyz
| Loading package bytestring-0.9.1.4 ... linking ... done.
| Loading package unix-2.3.1.0 ... linking ... done.
| Loading package filepath-1.1.0.1 ... linking ... done.
| Loading package old-locale-1.0.0.1 ... linking ... done.
| Loading package old-time-1.0.0.1 ... linking ... done.
| Loading package directory-1.0.0.2 ... linking ... done.
| Loading package process-1.0.1.0 ... linking ... done.
| Loading package syb ... linking ... done.
| Loading package array-0.2.0.0 ... linking ... done.
| Loading package random-1.0.0.1 ... linking ... done.
| Loading package haskell98 ... linking ... done.
| Prelude Main>
`----

Since I suspect that this might be a problem with the way I have installed
gch-6.10.1 I will explain how I have installed it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20090330/ba84cbd3/attachment-0001.htm

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

Message: 6
Date: Mon, 30 Mar 2009 13:15:50 -0400
From: "Brandon S. Allbery KF8NH" <[email protected]>
Subject: Re: [Haskell-beginners] can run in ghci but can't compile.
To: Anand Mitra <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

Skipped content of type multipart/alternative-------------- next part 
--------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url : 
http://www.haskell.org/pipermail/beginners/attachments/20090330/58cb6211/PGP-0001.bin

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

Message: 7
Date: Mon, 30 Mar 2009 23:24:28 +0530
From: Anand Mitra <[email protected]>
Subject: Re: [Haskell-beginners] can run in ghci but can't compile.
To: "Brandon S. Allbery KF8NH" <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

That does the job, Thanks !!

Just to understand what is happening under the hood I tried to resolve this
to the exact steps. The problem I faced seems to be equivalent of missing a
-L and -l in gcc. Looking at the man for ghc I did find it had the -l and -L
flags. Now I had to find the path and the name of the library. Did a find
over the location I have installed ghc I was able to short list the likely
candidates.

,----
| find /opt/ghc-6.10.1/ -type f |grep \\.a$
| ....
|
/opt/ghc-6.10.1/lib/ghc-6.10.1/bytestring-0.9.1.4/libHSbytestring-0.9.1.4.a
|
/opt/ghc-6.10.1/lib/ghc-6.10.1/bytestring-0.9.1.4/libHSbytestring-0.9.1.4_p.a
| ....
`----

and as expected adding the -l and -L in the ghc command line does the trick.

/opt/ghc-6.10.1/bin/ghc -L/opt/ghc-6.10.1/lib/ghc-6.10.1/bytestring-0.9.1.4/
-lHSbytestring-0.9.1.4 cp.hs

regards
-- 
Anand Mitra

On Mon, Mar 30, 2009 at 10:45 PM, Brandon S. Allbery KF8NH <
[email protected]> wrote:

> On 2009 Mar 30, at 13:12, Anand Mitra wrote:
>
> ,----
> | mi...@ravan:~/laptop/haskell/learn$ /opt/ghc-6.10.1/bin/ghc cp.hs
> | cp.o: In function `sB1_info':
> | (.text+0xab): undefined reference to
> `bytestringzm0zi9zi1zi4_DataziByteStringziLazzy_writeFile_closure'
> | cp.o: In function `sAW_info':
>
>
> Use "ghc --make".  ghci does this automatically.
>
> --
> brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [email protected]
> system administrator [openafs,heimdal,too many hats] [email protected]
> electrical and computer engineering, carnegie mellon university    KF8NH
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20090330/d84382e8/attachment.htm

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

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


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

Reply via email to