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:  the ($) function (was desugaring an example  from RWH)
      (John Hartnup)
   2.  ghc installation on mac osx 10.4.11(intel),      Xcode 2.4? (7stud)
   3. Re:  ghc installation on mac osx 10.4.11(intel),  Xcode 2.4?
      (Thomas Davie)
   4. Re:  ghc installation on mac osx 10.4.11(intel),  Xcode 2.4?
      (Daniel Fischer)
   5.  data constructor with IO type (Daneel Yaitskov)
   6. Re:  data constructor with IO type (Brent Yorgey)
   7.  Re: ghc installation on mac osx  10.4.11(intel), Xcode 2.4?
      (7stud)
   8.  Re: ghc installation on mac osx  10.4.11(intel), Xcode 2.4?
      (7stud)
   9.  Re: data constructor with IO type (Daneel Yaitskov)
  10.  Help with TAP implemation in haskell (Patrick LeBoutillier)


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

Message: 1
Date: Mon, 23 Feb 2009 19:21:06 +0000
From: John Hartnup <[email protected]>
Subject: Re: [Haskell-beginners] the ($) function (was desugaring an
        example         from RWH)
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

I had exactly the same confusion - not explaining ($) in RWH was major
dropped ball IMO.

>
> bogusTransfer qty fromBal toBal = do
>     fromQty <- atomically $ readTVar fromBal
>     [snip]
>

... is equivalent to:
bogusTransfer qty fromBal toBal = do
     fromQty <- atomically ( readTVar fromBal
     [snip]
     )

... so using ($) prevents accumulating a great big set of parentheses
to close at the end of a long block.


-- 
"There is no way to peace; peace is the way"


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

Message: 2
Date: Tue, 24 Feb 2009 07:21:49 +0000 (UTC)
From: 7stud <[email protected]>
Subject: [Haskell-beginners] ghc installation on mac osx
        10.4.11(intel), Xcode 2.4?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Hi,

I just bought Real World Haskell, and I'm trying to get the 
ghc compiler set up.  The installer for the latest version 
of ghc, 6.10.1, is for Leopard(osx 10.5).  What should
I install for osx 10.4.11(Tiger)?

Also, a question about "Beware of enumerating floating
point numbers" on p. 11.  The book doesn't explain
what it means to enumerate floating point numbers
without a step, so when it says to beware of 
the non-intuitive behavior of:

ghci> [1.0..1.8]

how would a reader know what the intuitive behavior is?
Is the step .1, .01, .001?  Is there a default 
step?  Who knows?


On p. 10 there is an error.  Below the last code example
 on the page, it says:

"In the latter case, the list is quite sensibly missing the
endpoint of the enumeration, because it isn't an 
element of the series we defined."

But the last line of the code example is this:

ghci> [10,9..1]
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

which quite clearly includes both endpoints.






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

Message: 3
Date: Tue, 24 Feb 2009 08:46:04 +0100
From: Thomas Davie <[email protected]>
Subject: Re: [Haskell-beginners] ghc installation on mac osx
        10.4.11(intel), Xcode 2.4?
To: 7stud <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes


On 24 Feb 2009, at 08:21, 7stud wrote:

> Hi,
>
> I just bought Real World Haskell, and I'm trying to get the
> ghc compiler set up.  The installer for the latest version
> of ghc, 6.10.1, is for Leopard(osx 10.5).  What should
> I install for osx 10.4.11(Tiger)?

Try using the version in MacPorts.

> Also, a question about "Beware of enumerating floating
> point numbers" on p. 11.  The book doesn't explain
> what it means to enumerate floating point numbers
> without a step, so when it says to beware of
> the non-intuitive behavior of:
>
> ghci> [1.0..1.8]
>
> how would a reader know what the intuitive behavior is?
> Is the step .1, .01, .001?  Is there a default
> step?  Who knows?

I'd say that if you can't figure out what it should do, that's pretty  
non intuitive, no?

Bob


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

Message: 4
Date: Tue, 24 Feb 2009 11:25:53 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] ghc installation on mac osx
        10.4.11(intel), Xcode 2.4?
To: 7stud <[email protected]>, [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="iso-8859-1"

Am Dienstag, 24. Februar 2009 08:21 schrieb 7stud:
> Hi,
>
> Also, a question about "Beware of enumerating floating
> point numbers" on p. 11.  The book doesn't explain
> what it means to enumerate floating point numbers
> without a step, so when it says to beware of
> the non-intuitive behavior of:
>
> ghci> [1.0..1.8]
>
> how would a reader know what the intuitive behavior is?
> Is the step .1, .01, .001?  Is there a default
> step?  Who knows?
>

Experienced Haskellers know :-)
The default step is 1, and

Prelude> [1.0 .. 1.8]
[1.0,2.0]

, which is what is meant by "the non-intuitive behaviour".
Of course, a learner won't know, so a request to the authors: elaborate that 
in the second edition.

The fact behind it is that [a .. b] is syntactic sugar for

enumFromTo a b

, enumFromTo is a method in the class Enum. As the name suggests, this class 
is for types where you can enumerate the elements, every element - except 
boundary elements - should have a well defined predecessor and successor.
So, enumFromTo a b is in these cases the sequence of elements c with 
index a <= index c <= index b, the indices increasing by 1.
This doesn't make much sense for floating point types or Rational, of course.
However, arithmetic sequences do make a lot of sense for these types, so they 
are made instances of the class Enum, too. Since their elements don't have a 
natural indexing, these instances are by necessity somewhat broken.
The enumFrom and enumFromTo methods proceed in steps of 1, which in absence of 
a reasonable successor function is probably the best choice. However, 
enumFromTo a b doesn't stop when the value exceeds b, but when it exceeds 
b+1/2.
The behaviour is defined in section 6.3.4 of the Haskell report.

>
> On p. 10 there is an error.  Below the last code example
>  on the page, it says:
>
> "In the latter case, the list is quite sensibly missing the
> endpoint of the enumeration, because it isn't an
> element of the series we defined."
>
> But the last line of the code example is this:
>
> ghci> [10,9..1]
> [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
>
> which quite clearly includes both endpoints.
>

They probably meant to write

[10,8 .. 1].




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

Message: 5
Date: Tue, 24 Feb 2009 20:04:33 +0300
From: Daneel Yaitskov <[email protected]>
Subject: [Haskell-beginners] data constructor with IO type
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii


Hi All,

I'd like to know does it exist a method which allow to construct the TestB
type without a temporary variable such as the TestA constructor.

---
module Main where

import Monad
import Control.Concurrent
data TestA = TestA (MVar Bool)
xGetA (TestA x) = x
data TestB = TestB { xGetB ::  MVar Bool } 

---
main =
 do tmp <- newMVar False
   let t = TestB { xGetB  = tmp } in
       do vt <- takeMVar t
          putStrLn ("HELLO" ++ show vt)
---

main = do
 t <- liftM TestA  (newMVar False)
 vt <- takeMVar (xGetA t)
 putStrLn ("HELLO" ++ show vt)

---

Daneel Yaitskov



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

Message: 6
Date: Tue, 24 Feb 2009 12:30:23 -0500
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] data constructor with IO type
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Tue, Feb 24, 2009 at 08:04:33PM +0300, Daneel Yaitskov wrote:
> 
> Hi All,
> 
> I'd like to know does it exist a method which allow to construct the TestB
> type without a temporary variable such as the TestA constructor.
> 
> ---
> module Main where
> 
> import Monad
> import Control.Concurrent
> data TestA = TestA (MVar Bool)
> xGetA (TestA x) = x
> data TestB = TestB { xGetB ::  MVar Bool } 
> 
> ---
> main =
>  do tmp <- newMVar False
>    let t = TestB { xGetB  = tmp } in
>        do vt <- takeMVar t
>           putStrLn ("HELLO" ++ show vt)
> ---
> 
> main = do
>  t <- liftM TestA  (newMVar False)
>  vt <- takeMVar (xGetA t)
>  putStrLn ("HELLO" ++ show vt)
> 
> ---
> 
> Daneel Yaitskov

Hi Daneel,

Note that record syntax like

> data TestB = TestB { xGetB ::  MVar Bool }

only adds capabilities; you can still use TestB as if it was defined
without record syntax, like TestA.  So you are not required to use the 

  TestB {xGetB = tmp} 

syntax to create a TestB, you could also just say 'TestB tmp'.  So the
second code example should work fine if you just replace all the 'A's
with 'B's.  

Does this answer your question?  I must admit that I am not entirely
sure what you are asking, so if this doesn't address your question
feel free to clarify.

-Brent


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

Message: 7
Date: Tue, 24 Feb 2009 20:16:13 +0000 (UTC)
From: 7stud <[email protected]>
Subject: [Haskell-beginners] Re: ghc installation on mac osx
        10.4.11(intel), Xcode 2.4?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Thomas Davie <tom.davie <at> gmail.com> writes:

> 
> 
> On 24 Feb 2009, at 08:21, 7stud wrote:
> 
> > Hi,
> >
> > I just bought Real World Haskell, and I'm trying to get the
> > ghc compiler set up.  The installer for the latest version
> > of ghc, 6.10.1, is for Leopard(osx 10.5).  What should
> > I install for osx 10.4.11(Tiger)?
> 
> Try using the version in MacPorts.
> 

I did some more digging around at haskell.org, and I
discovered a download for 6.8.2 for mac osx 10.4, so
I downloaded and installed that.  Will that be ok?

For anyone who can't figure out how to install
ghc, cd into the ghc folder that is created when you
unzip the download.  Then read the INSTALL file.
To install, I did the following:

$ ./configure

$ sudo make install

At the end of which, I got the message:
-----------
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!
-----------


> > Also, a question about "Beware of enumerating floating
> > point numbers" on p. 11.  The book doesn't explain
> > what it means to enumerate floating point numbers
> > without a step, so when it says to beware of
> > the non-intuitive behavior of:
> >
> > ghci> [1.0..1.8]
> >
> > how would a reader know what the intuitive behavior is?
> > Is the step .1, .01, .001?  Is there a default
> > step?  Who knows?
> 
> I'd say that if you can't figure out what it should do, that's pretty  
> non intuitive, no?
> 

I would agree.  :)







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

Message: 8
Date: Tue, 24 Feb 2009 20:27:20 +0000 (UTC)
From: 7stud <[email protected]>
Subject: [Haskell-beginners] Re: ghc installation on mac osx
        10.4.11(intel), Xcode 2.4?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Daniel Fischer <daniel.is.fischer <at> web.de> writes:
>
> Experienced Haskellers know 
> The default step is 1, and
> 

Thanks for the explanation.

> >
> > But the last line of the code example is this:
> >
> > ghci> [10,9..1]
> > [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
> >
> > which quite clearly includes both endpoints.
> >
> 
> They probably meant to write
> 
> [10,8 .. 1].
> 


Actually, after examining the text several more times, 
the code block has three examples:

ghci> [1.0, 1.25..2.0]
[1.0,1.25,1.5,1.75,2.0]
ghci> [1, 4..15]
[1,4,7,10,13]
ghci> [10, 9..1]
[10,9,8,7,6,5,4,3,2,1]

and apparently "In the latter case" was meant to refer
 to the middle example.
 









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

Message: 9
Date: Wed, 25 Feb 2009 00:12:28 +0300
From: Daneel Yaitskov <[email protected]>
Subject: [Haskell-beginners] Re: data constructor with IO type
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Brent Yorgey <[email protected]> writes:

>
> Note that record syntax like
>
>> data TestB = TestB { xGetB ::  MVar Bool }
>
> only adds capabilities; you can still use TestB as if it was defined
> without record syntax, like TestA.  So you are not required to use the 
>
>   TestB {xGetB = tmp} 
>
> syntax to create a TestB, you could also just say 'TestB tmp'.  So the
> second code example should work fine if you just replace all the 'A's
> with 'B's.  
>
> Does this answer your question?  I must admit that I am not entirely
> sure what you are asking, so if this doesn't address your question
> feel free to clarify.
>
> -Brent
I know about it. I mean how to save names of arguments. 
Because usually data structures is complex and they contain many fields.
Method which doesn't the names of the arguments requires to give the 
values for all members. Sometimes some subsets of one structure calculate
 themselves at other places or structure contains many fields. One part of
them get themselves from the pure functions and other do from the action
functions.

Daneel Yaitskov



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

Message: 10
Date: Tue, 24 Feb 2009 20:32:49 -0500
From: Patrick LeBoutillier <[email protected]>
Subject: [Haskell-beginners] Help with TAP implemation in haskell
To: beginners <[email protected]>
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hi,

As a learning exercise, I'm trying to make a Haskell module (my first)
that implements a TAP library (http://testanything.org/).

The library basically provides some functions to perform unit tests
and keeps track of some state. It also performs quite a bit of IO as
it goes a long.

As a first step I'm loosely basing my code on a Java implementation.
You can find the code here:
http://svn.solucorp.qc.ca/repos/solucorp/JTap/trunk/JTap.java.

I've setup my TapState data structure and a monad transformer to be
able to keep state and do IO within the same functions:

  data TapState = TapState {
    planSet :: Bool,
    noPlan :: Bool,
    skipAll :: Bool,
    testDied :: Bool,
    expectedTests :: Int,
    executedTests :: Int,
    failedTests :: Int
  } deriving (Show)

  type TAP a = StateT TapState IO a

In the Java version there is a function called cleanup that is called
after all the tests are performed to determine the return code and
print some diagnostics:

private int cleanup(){
        int rc = 0 ;

        if (! plan_set){
                diag("Looks like your test died before it could output 
anything.") ;
                return rc ;
        }

        if (test_died){
                diag("Looks like your test died just after " + executed_tests + 
".") ;
                return rc ;
        }

        if ((! skip_all)&&(no_plan)){
                print_plan(executed_tests) ;
        }

        if ((! no_plan)&&(expected_tests < executed_tests)) {
                diag("Looks like you planned " + expected_tests + " test" +
(expected_tests > 1 ? "s" : "") + " but ran "
                        + (executed_tests - expected_tests) + " extra.") ;
                rc = -1 ;
        }

        if ((! no_plan)&&(expected_tests > executed_tests)) {
                diag("Looks like you planned " + expected_tests + " test" +
(expected_tests > 1 ? "s" : "") + " but only ran "
                        + executed_tests + ".") ;
        }

        if (failed_tests > 0){
                diag("Looks like you failed " + failed_tests + " test" +
(failed_tests > 1 ? "s" : "") + " of " + executed_tests + ".") ;
        }

        return rc ;
}


I'm having problems implementing the equivalent of this function in
haskell. Inside a do block, is there a way to terminate the function
immediately and return a result ("return" in the imperative sense, not
the Haskell sense)? If not, must one really use deeply nested
if/then/else statements to treat these special cases? All I could come
up was this, which I find quite ugly:

_cleanup :: Int -> TAP Int
_cleanup rc = do
    ts <- get
    if (not $ planSet ts)
        then do
            diag "Looks like your test died before it could output anything."
            return rc
        else if (testDied ts)
            then do
                diag $ "Looks like your test died just after " ++
(show $ executedTests ts)
                return rc
            else ...


Thanks a lot,

Patrick

Note: If it helps, you can find my Haskell code here:
http://svn.solucorp.qc.ca/repos/solucorp/JTap/trunk/tap.hs


-- 
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada


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

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


End of Beginners Digest, Vol 8, Issue 23
****************************************

Reply via email to