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. Re:  question about show -- RWH chapter 5 (Peter Verswyvelen)
   2. Re:  question about show -- RWH chapter 5 (Daniel Fischer)
   3.  Re: question about show -- RWH chapter 5 (7stud)
   4.  question about styles of recursion (Michael Mossey)
   5.  Re: question about show -- RWH chapter 5 (7stud)
   6.  Re: question about show -- RWH chapter 5 (7stud)
   7. Re:  question about show -- RWH chapter 5
      (Brandon S. Allbery KF8NH)


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

Message: 1
Date: Thu, 26 Mar 2009 16:47:38 +0100
From: Peter Verswyvelen <[email protected]>
Subject: Re: [Haskell-beginners] question about show -- RWH chapter 5
To: 7stud <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Well, for JSON, I think the rendered string must be enclosed in double
quotes, which is what the show instance for String does.
So

renderJValue (JString s)    = show s

is not the same as

renderJValue (JString s)    = s

You can easily see this with GHCi. A copy from my Windows session:

C:\>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> let s = "Haskell"
Prelude> s
"Haskell"
Prelude> show s
"\"Haskell\""
Prelude> show (show s)
"\"\\\"Haskell\\\"\""
Prelude>






On Thu, Mar 26, 2009 at 4:41 PM, 7stud <[email protected]> wrote:

> In chapter 5, RWH defines a JValue data type like this:
>
>
> SimpleJSON.hs:
> --------------
>
> module SimpleJSON
>    (
>     JValue(..)
>    ) where
>
> data JValue = JNumber Double
>            | JString String
>            | JArray [JValue]
>            | JObject [(String, JValue)]
>            | JBool Bool
>            | JNull
>              deriving (Eq, Ord, Show)
>
> ------------
>
>
> Then RWH defines some functions like this:
>
> PutJSON.hs:
> ----------
> module PutJSON where
>
> import SimpleJSON
>
> renderJValue::JValue->String
> renderJValue (JNumber f)    = show f
> renderJValue (JString s)    = show s
> renderJValue (JBool True)   = "true"
> renderJValue (JBool False)  = "false"
> renderJValue JNull          = "null"
> ----------
>
> My question is about the function:
>
> renderJValue (JString s) = show s
>
> A JString value contains a string, so why does the function use
> show to convert s to a string?  Why isn't that function defined
> like this:
>
> renderJValue (JString s) = s
>
> Using that modified function seems to work:
>
>
> Main.hs:
> ---------
> module Main () where
>
> import SimpleJSON
> import PutJSON
>
> main = let x = JString "hello"
>       in putStrLn (renderJValue x)
>
>
> $ ghc -o simple Main.hs PutJSON.hs SimpleJSON.hs
> /usr/libexec/gcc/i686-apple-darwin8/4.0.1/ld: warning -F: directory name
> (/Users/me/Library/Frameworks) does not exist
>
> $ simple
> hello
>
> Also can anyone tell me why I always get that warning?
>
> Thanks
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20090326/6ff499d7/attachment-0001.htm

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

Message: 2
Date: Thu, 26 Mar 2009 16:53:58 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] question about show -- RWH chapter 5
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="iso-8859-1"

Am Donnerstag 26 März 2009 16:41:47 schrieb 7stud:
> In chapter 5, RWH defines a JValue data type like this:
>
>
> SimpleJSON.hs:
> --------------
>
> module SimpleJSON
>     (
>      JValue(..)
>     ) where
>
> data JValue = JNumber Double
>
>             | JString String
>             | JArray [JValue]
>             | JObject [(String, JValue)]
>             | JBool Bool
>             | JNull
>
>               deriving (Eq, Ord, Show)
>
> ------------
>
>
> Then RWH defines some functions like this:
>
> PutJSON.hs:
> ----------
> module PutJSON where
>
> import SimpleJSON
>
> renderJValue::JValue->String
> renderJValue (JNumber f)    = show f
> renderJValue (JString s)    = show s
> renderJValue (JBool True)   = "true"
> renderJValue (JBool False)  = "false"
> renderJValue JNull          = "null"
> ----------
>
> My question is about the function:
>
> renderJValue (JString s) = show s
>
> A JString value contains a string, so why does the function use
> show to convert s to a string?  Why isn't that function defined
> like this:
>
> renderJValue (JString s) = s

The JSON values are rendered so that they can be parsed at the 
other end. The parser must have the string enclosed in quotation 
marks for that, also some characters need to be escaped.
Consider having 
JString "true"
JString "[true, null, false]"
JString "This is a\nmultiline text.\b!"

>
> Using that modified function seems to work:
>
>
> Main.hs:
> ---------
> module Main () where
>
> import SimpleJSON
> import PutJSON
>
> main = let x = JString "hello"
>        in putStrLn (renderJValue x)
>
>
> $ ghc -o simple Main.hs PutJSON.hs SimpleJSON.hs
> /usr/libexec/gcc/i686-apple-darwin8/4.0.1/ld: warning -F: directory 
name
> (/Users/me/Library/Frameworks) does not exist
>
> $ simple
> hello
>
> Also can anyone tell me why I always get that warning?

Does the directory exist? If it exists, is in in the linker path?

>
> Thanks




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

Message: 3
Date: Thu, 26 Mar 2009 16:04:19 +0000 (UTC)
From: 7stud <[email protected]>
Subject: [Haskell-beginners] Re: question about show -- RWH chapter 5
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Peter Verswyvelen <bugfact <at> gmail.com> writes:
>
> Well, for JSON, I think the rendered string must be enclosed in double 
> quotes, 
> which is what the show instance for String does.
> 

Ahh.  I see.  My version yields this output:

main = let x = JString "hello" 
           y = JNumber 10
           rx = renderJValue x
           ry = renderJValue y
       in putStrLn ("[" ++ rx ++ ", " ++ ry ++ "]")


$ simple
[hello, 10.0]

...and that is not correct JSON format. hello looks like a variable 
name--not a string.  The books version produces:

["hello", 10.0]

which is what a javascript array that contains a string looks like.

Thanks.









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

Message: 4
Date: Thu, 26 Mar 2009 09:19:18 -0700
From: Michael Mossey <[email protected]>
Subject: [Haskell-beginners] question about styles of recursion
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

In RWH, in the exercises at the end of the book, I was told to write a 
function that averages the integer values in a list. I wanted to do this 
using on the tools we had been presented, which did not include 
'length'. So I thought of writing a recursive function in which each 
case passes an accumulator of the "sum so far" as well as a count of 
node "up to the point", and the base case does the actual division. I 
was wondering if there is a better way of doing it (using the just ideas 
up to chapter 3, so no length, no higher order functions, no foldr/foldl 
or map).

myAvg' :: Int -> [Int] -> [ Double ] -> Double
myAvg' sum count []     = sum / fromIntegral count
myAvg' sum count (x:xs) = myAvg' (x + sum) (n + 1) xs

myAvg :: [Double] -> Double
myAvg xs = myAvg' 0 0 xs

Thanks,
Mike


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

Message: 5
Date: Thu, 26 Mar 2009 16:20:46 +0000 (UTC)
From: 7stud <[email protected]>
Subject: [Haskell-beginners] Re: question about show -- RWH chapter 5
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Daniel Fischer <daniel.is.fischer <at> web.de> writes:

> > $ ghc -o simple Main.hs PutJSON.hs SimpleJSON.hs
> > /usr/libexec/gcc/i686-apple-darwin8/4.0.1/ld: warning -F: directory 
> name
> > (/Users/me/Library/Frameworks) does not exist
> >
> > $ simple
> > hello
> >
> > Also can anyone tell me why I always get that warning?
> 
> Does the directory exist? If it exists, is in in the linker path?
> 

No it doesn't exist.  There is a directory:

/Library/Frameworks

This is what I did to install ghc:

1) I downloaded GMP.framework and GNUreadline.framework, which my mac 
automatically unzipped and placed on my desktop.  I then dragged the 
resulting two folders into /Library/Frameworks as per the instructions at:

http://www.haskell.org/ghc/download_ghc_682.html#macosxintel

2) I downloaded ghc-6.8.2

3) I unzipped an untared into /Users/me/my_tar_extractions

4) I cd'ed into the newly created ghc-6.8.2 folder.

5) I read the INSTALL document in the ghc-6.8.2 folder.

6) I ran the command:

$ ./configure

7) Then I ran the command:

$ sudo make install

8)  At the end of the install output, I got a message that said:
-------------
Installation of ghc-6.8.2 was successful.

To use, add /usr/local/bin to your PATH.

Warning: this binary distribution does NOT contain documentation!
--------------

9) I appended /usr/local/bin onto the PATH in ~/.bash_profile.


After unzipping and untaring ghc, should I have put the 
ghc-6.8.2 folder in /Library/Frameworks like I did with 
GMP.framework and GNUreadline.framework?  Can I still do that?







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

Message: 6
Date: Thu, 26 Mar 2009 16:26:06 +0000 (UTC)
From: 7stud <[email protected]>
Subject: [Haskell-beginners] Re: question about show -- RWH chapter 5
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

7stud <bbxx789_05ss <at> yahoo.com> writes:
> 5) I read the INSTALL document in the ghc-6.8.2 folder.
> 

This is what INSTALL says:

----
This is the INSTALL instructions for a binary distribution of GHC. For
more details on what on earth this package is up to, please consult
the README and ANNOUNCE.

This distribution can be installed in a location of your choosing.

To set the ball rolling, run the configure script (as usual, run the
script with --help to see what options it supports).  eg. to set up
the package for installing in directory <my-dir>, use

        ./configure --prefix=<my-dir>

The default installation directory is /usr/local.

The configure script will figure out what platform you're running on,
and a couple of other interesting pieces of trivia, which it will then
fill in the Makefile.in template to give you a real Makefile.  If
you're of a paranoid persuasion, you might want to take a look at this
Makefile to see if the information is correct.

Now run:

        make install 

(`make show-install-setup' prints the details of where the different
pieces of the bundle are heading when -- possibly helpful).

For more information, full GHC documentation is available from the
main GHC site:

  http://www.haskell.org/ghc

Bug reports/suggestions for improvement to the installation
procedure/setup (as well as other GHC related troubles you're
experiencing, of course), gratefully received.  Bug reporting
instructions are here:

  http://www.haskell.org/ghc/reportabug

Enjoy,
-- The GHC Team.
---------------

It didn't say anything about putting the ghc folder in /Library/Frameworks.



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

Message: 7
Date: Thu, 26 Mar 2009 12:43:59 -0400
From: "Brandon S. Allbery KF8NH" <[email protected]>
Subject: Re: [Haskell-beginners] question about show -- RWH chapter 5
To: 7stud <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

On 2009 Mar 26, at 11:41, 7stud wrote:
> $ ghc -o simple Main.hs PutJSON.hs SimpleJSON.hs
> /usr/libexec/gcc/i686-apple-darwin8/4.0.1/ld: warning -F: directory  
> name
> (/Users/me/Library/Frameworks) does not exist


My guess is that the binary ghc was compiled to allow for use of  
private frameworks, so you get an unnecessary warning when you don't  
have any.  Just create ~/Library/Frameworks if you want the warning to  
go away.

-- 
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 --------------
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/20090326/7e9891cb/PGP.bin

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

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


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

Reply via email to