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:  Why doesn't ghci load this? (Brandon S. Allbery KF8NH)
   2.  Re: Why doesn't ghci load this? (7stud)
   3.  how do you use a package (.cabal)? (7stud)
   4. Re:  how do you use a package (.cabal)? (Brandon S. Allbery KF8NH)
   5.  Re: how do you use a package (.cabal)? (7stud)
   6. Re:  Re: how do you use a package (.cabal)?
      (Brandon S. Allbery KF8NH)
   7. Re:  beginner's type error (Brent Yorgey)
   8. Re:  beginner's type error (Brent Yorgey)
   9. Re:  Simple laplace solver (Francesco Bochicchio)


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

Message: 1
Date: Sat, 28 Mar 2009 01:20:47 -0400
From: "Brandon S. Allbery KF8NH" <[email protected]>
Subject: Re: [Haskell-beginners] Why doesn't ghci load this?
To: [email protected]
Cc: beginners beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

On 2009 Mar 28, at 0:59, Jeff Lasslett wrote:
> myGroupBy :: (a -> a -> Bool) -> [a] -> [[a]]
> myGroupBy p xs =
> foldr step [[]] xs
> where
>  -- step :: a -> [ [ a ] ] -> [ [ a ] ]
>  step x acc@( ys : yss )
>   | null ys                      = [ x ] : []
>   | p x ( head ys )              = ( x : ys ) : yss
>   | ( p x ( head ys ) ) == False = [ x ] : acc

In Haskell98, the type "a" in step is not the same as the one in  
myGroupBy.  If you use the ScopedTypeVariables extension (see the ghc  
manual; just adding the option won't work) you can write the type.

-- 
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/20090328/9849f6ad/PGP-0001.bin

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

Message: 2
Date: Sat, 28 Mar 2009 06:01:19 +0000 (UTC)
From: 7stud <[email protected]>
Subject: [Haskell-beginners] Re: Why doesn't ghci load this?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Brandon S. Allbery KF8NH <allbery <at> ece.cmu.edu> writes:

> 
> On 2009 Mar 28, at 0:59, Jeff Lasslett wrote:
> > myGroupBy :: (a -> a -> Bool) -> [a] -> [[a]]
> > myGroupBy p xs =
> > foldr step [[]] xs
> > where
> >  -- step :: a -> [ [ a ] ] -> [ [ a ] ]
> >  step x acc@( ys : yss )
> >   | null ys                      = [ x ] : []

I wonder whether that line does anything?  foldr is defined like
this:

foldr step zero (x:xs) = step x (foldr step zero xs)

So it seems to me that when the step function doesn't affect
either the accumulator(=zero) or xs, then the step function
won't have any effect on the result foldr produces. 

The return value from your 'null ys' guard does not affect
xs, nor does it change the accumulator acc.  So how does
it affect the result of foldr?











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

Message: 3
Date: Sat, 28 Mar 2009 06:35:12 +0000 (UTC)
From: 7stud <[email protected]>
Subject: [Haskell-beginners] how do you use a package (.cabal)?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

In chapter 5 in RWH, they show you how to create, configure,
and install a package.  This is the final step:

...mypretty$ runghc Setup install
Installing: /usr/local/lib/mypretty-0.1/ghc-6.8.2
Setup: /usr/local/lib/mypretty-0.1: createDirectory: permission
 denied (Permission denied)

.../mypretty$ sudo runghc Setup install
Password:
Installing: /usr/local/lib/mypretty-0.1/ghc-6.8.2
Registering mypretty-0.1...
Reading package info from "dist/installed-pkg-config" ... done.
Saving old package config file... done.
Writing new package config file... done.

$ ghc-pkg list
/usr/local/lib/ghc-6.8.2/package.conf:
    Cabal-1.2.3.0, GLUT-2.1.1.1, HUnit-1.2.0.0, OpenAL-1.3.1.1,
    OpenGL-2.2.1.1, QuickCheck-1.1.0.0, array-0.1.0.0, base-3.0.1.0,
    bytestring-0.9.0.1, cgi-3001.1.5.1, containers-0.1.0.1,
    directory-1.0.0.0, fgl-5.4.1.1, filepath-1.1.0.0, (ghc-6.8.2),
    haskell-src-1.0.1.1, haskell98-1.0.1.0, hpc-0.5.0.0, html-1.0.1.1,
    mtl-1.1.0.0, mypretty-0.1, network-2.1.0.0, old-locale-1.0.0.0,
    old-time-1.0.0.0, packedstring-0.1.0.0, parallel-1.0.0.0,
    parsec-2.1.0.0, pretty-1.0.0.0, process-1.0.0.0, random-1.0.0.0,
    readline-1.0.1.0, regex-base-0.72.0.1, regex-compat-0.71.0.1,
    regex-posix-0.72.0.2, rts-1.0, stm-2.1.1.0,
    template-haskell-2.2.0.0, time-1.1.2.0, unix-2.3.0.0,
    xhtml-3000.0.2.1

The mypretty package is in that list.  But what does that do for
me? How do I access that package? The .cabal file has this 
text in it:

library
   Exposed-Modules: SimpleJSON
                    PrettyJSON
                    Prettify
   Build-Depends: base >= 2.0

                              
But I created a Main.hs file that imported the
"exposed modules":


module Main () where

import Prettify
import PrettyJSON
import SimpleJSON


main = let s = JString "hello world"
           aDoc = renderJValue s
       in printPrettified aDoc

--JString is a JValue value constructor and JValue is defined in 
SimpleJSON.hs

--renderJVAlue is a function defined in PrettyJSON.hs, and it returns
a data type that is defined in Prettify.js

--printPrettified is a function defined in PrettyJSON.hs


This is what happens:

$ ghc -c Main.hs
~/2testing/dir3$ ghc -o test Main.hs
compilation IS NOT required
/usr/libexec/gcc/i686-apple-darwin8/4.0.1/ld: warning -F: directory name 
(/Users/me/Library/Frameworks) does not exist

/usr/libexec/gcc/i686-apple-darwin8/4.0.1/ld: Undefined symbols:
___stginit_myprettyzm0zi1_Prettify_
___stginit_myprettyzm0zi1_PrettyJSON_
___stginit_myprettyzm0zi1_SimpleJSON_
_myprettyzm0zi1_PrettyJSON_printPrettified_closure
_myprettyzm0zi1_PrettyJSON_renderJValue_closure
_myprettyzm0zi1_SimpleJSON_JString_static_info
collect2: ld returned 1 exit status

I googled cabal tutorials, but I can't find anything that
tells me how to access an installed package.






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

Message: 4
Date: Sat, 28 Mar 2009 02:52:36 -0400
From: "Brandon S. Allbery KF8NH" <[email protected]>
Subject: Re: [Haskell-beginners] how do you use a package (.cabal)?
To: 7stud <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

On 2009 Mar 28, at 2:35, 7stud wrote:
> $ ghc -c Main.hs
> ~/2testing/dir3$ ghc -o test Main.hs


If you're not using the cabal framework to build your program, you  
want to use "ghc --make" so it will chase down the package  
dependencies.  Otherwise you would need to say "ghc -package mypretty".

-- 
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/20090328/ca64aaf2/PGP-0001.bin

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

Message: 5
Date: Sat, 28 Mar 2009 07:40:39 +0000 (UTC)
From: 7stud <[email protected]>
Subject: [Haskell-beginners] Re: how do you use a package (.cabal)?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Brandon S. Allbery KF8NH <allbery <at> ece.cmu.edu> writes:

> 
> On 2009 Mar 28, at 2:35, 7stud wrote:
> > $ ghc -c Main.hs
> > ~/2testing/dir3$ ghc -o test Main.hs
> 
> If you're not using the cabal framework to build your program, 

I thought I was.

> you  
> want to use "ghc --make" so it will chase down the package  
> dependencies.  Otherwise you would need to say "ghc -package mypretty".
> 

Based on what I did to install the package, how am I supposed to use
the package in a program?  The book doesn't give any clue.










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

Message: 6
Date: Sat, 28 Mar 2009 03:43:15 -0400
From: "Brandon S. Allbery KF8NH" <[email protected]>
Subject: Re: [Haskell-beginners] Re: how do you use a package
        (.cabal)?
To: 7stud <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

On 2009 Mar 28, at 3:40, 7stud wrote:
> Brandon S. Allbery KF8NH <allbery <at> ece.cmu.edu> writes:
>> On 2009 Mar 28, at 2:35, 7stud wrote:
>>> $ ghc -c Main.hs
>>> ~/2testing/dir3$ ghc -o test Main.hs
>>
>> If you're not using the cabal framework to build your program,
>
> I thought I was.

You used it to build your package.  You're using ghc directly to build  
your program, not doing "runhaskell Setup.hs build" or "cabal install".

>> you
>> want to use "ghc --make" so it will chase down the package
>> dependencies.  Otherwise you would need to say "ghc -package  
>> mypretty".
>
> Based on what I did to install the package, how am I supposed to use
> the package in a program?  The book doesn't give any clue.

That is exactly what you just quoted.

-- 
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/20090328/ad675927/PGP-0001.bin

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

Message: 7
Date: Sat, 28 Mar 2009 08:29:47 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] beginner's type error
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Fri, Mar 27, 2009 at 11:28:54AM -0400, Edward Z. Yang wrote:
> On Fri, 27 Mar 2009, Brent Yorgey wrote:
>>> thing n = n + fromIntegral (round (sqrt n))
>
> thing :: Floating a => a -> a
>
>>> thing n = n + round (sqrt (fromIntegral n))
>
> thing :: Integral a => a -> a
>
> That is, the return types of the method are different?

Right!

-Brent


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

Message: 8
Date: Sat, 28 Mar 2009 08:39:55 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] beginner's type error
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Fri, Mar 27, 2009 at 07:44:05PM +0000, Ivan Moore wrote:
> Many thanks for the fantastic answers.
> 
> I have a question related to your answer
> 
> > The reason (which is a bit confusing) is that it typechecks just
> > fine---if there *were* a type which is an instance of both Integral
> > and Floating (and I guess round needs RealFrac as well), n could have
> > that type.  There isn't such a type in the standard libraries, but in
> > theory you could make up your own type which is an instance of both.
> 
> If there were such a type, could "10" have that type and then would my
> problem have not existed? (in which case, why doesn't it!?)
> (an answer of - "ask again when you've used the language a bit more"
> would be perfectly fine if it requires a lot
> more understanding of the language to understand the answer than a
> newbie like me has - I'm just curious)
> 

If there were such a type, and if it were one of the types to which
ghci was allowed to default, then you would not have had a problem.
But if you look at the methods of the Integral and Floating classes,
you will see that such a type would likely be silly.  You can't really
have a type which is simultaneously Integral (i.e. whole numbers, with
no fractional part) and Floating (i.e. floating point numbers which
can be divided, square rooted, etc.).  To have a type be an instance
of both would require a radical reinterpretation of what these type
classes mean.

-Brent


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

Message: 9
Date: Sat, 28 Mar 2009 15:58:51 +0100
From: Francesco Bochicchio <[email protected]>
Subject: Re: [Haskell-beginners] Simple laplace solver
To: "Edward Z. Yang" <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

2009/3/27 Edward Z. Yang <[email protected]>

> Hello all,
>

Hi


>
> average :: Fractional a => [a] -> a
> average list = sum list / fromIntegral (length list)
>

There was a thread on this ML which was about an implementation of average
which avoids
traversing the list twice, one for 'sum' and one for 'length'. You could use
it, if you care for
performance and your list is long enough to matter

Ciao
----------
FB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20090328/b6153e56/attachment.htm

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

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


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

Reply via email to