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: edit-compile-test loop (Joe Fredette)
2. StateT, list monad (Michael Mossey)
3. Re: StateT, list monad (Daniel Fischer)
4. proxy (Hong Yang)
5. Distributing executables (Joe Van Dyk)
6. Haskell type system (informationen)
7. Re: Haskell type system (Peter Verswyvelen)
----------------------------------------------------------------------
Message: 1
Date: Mon, 21 Sep 2009 18:38:48 -0400
From: Joe Fredette <[email protected]>
Subject: Re: [Haskell-beginners] edit-compile-test loop
To: Tom Doris <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
Well, basically I switch from doing manual "testing" (entering
functions with test arguments by hand into ghci, checking types w/ the
inferrer, etc.) to compiling via cabal build (which requires me to
make sure I've got all the appropriate modules listed in the
appropriate places, make sure I'm not importing hidden modules, etc)
and running a test suite (typically QuickCheck properties with some
HUnit thrown in around the IO stuff and for corner cases of functions
(eg, making sure things fail gracefully when I have to write a partial
function, etc)) and working generally more as if I were writing in a
language like Java (where most of my dev cycle is interacting with
JUnit, rather than a interpreter). Typically it works out to:
1> edit some stuff
2> cabal build
3> fix any errors; goto 1 else continue
4> run test suite [see 1]
5> if any tests fail, and that wasn't expected, fix the issue; goto 1
else continue
6> goto 1 until ready for release.
Towards the release date, this process helps me add functionality
slower, and ensure everything is actually doing what it's supposed to.
I tend to work on projects solo, so I'll do various naughty things
like develop without writing alot of tests or documenting, etc. When I
get ready to release, I really want to make sure I've covered
everything that needs to be tested with tests, documented everything
appropriately. As I code (even before this part of the project) I
generally keep track of what I should write tests for, even if I
haven't written the test yet. During this phase I build up the test
suite to cover all the things I've written down, and the test suite
kind of becomes part of the specification at that point. If something
in the future causes an early test to fail, then that change "breaks"
the program, if it causes a current test to fail, then I might want to
see if that test is really ensuring the property I want.
I should note, I'm not a CS-guy, I'm a math guy, and this kind of
methodology is more like when I write a math paper than what I think
most people do when they code. When I have a ECT loop for math papers,
it starts with me making wild conjectures and "testing" them (trying
to come up with proof sketches), later that turns to this slower
process of actually, formally proving things (the compiling part of
this cycle) and finally it hits the, "Now make it pretty" phase, where
I eliminate superfluous arguments/lemmas, rework proofs to flow
better, etc (the "make sure the tests pass" phase). I don't know if
this is similar to "normal" dev cycles, but it does me nicely. :)
HTH
/Joe
[1] right now I use my own little hacked up testrunning script (just
loads the stuff in ghci, and I have one function that sits in a base
"test" directory, underwhich the project module hierarchy is mirrored.
So if I have, as I do now, Text/HWN/Parser/HWN.hs, then I also have
Test/Text/HWN/Parser/HWN_Test.hs. in the Test directory I have
Test_Harness.hs, which has a main function which runs all the tests in
the directories below it. Each directory has a similar Test_Harness.hs
(though all the names are different) which loads all the tests of the
directories below it, and exports a single test group. All of this is
manual, though I've been planning a kind of manager thing for it
lately. But thats a story for another day.
On Sep 21, 2009, at 6:22 PM, Tom Doris wrote:
> Thanks, this is very helpful; can you give more detail about your
> process once you've transitioned to a "proper test harness/cabal
> build", how does this usually hang together?
>
>
> 2009/9/21 Joe Fredette <[email protected]>
> Assuming I'm starting a brand-new project, it starts by creating a
> file in my code directory. initing darcs there, creating the .cabal
> file, and creating a basic module hierarchy. After that, I `touch` a
> couple of files. add the standard license/description/other header
> info...
>
> When I'm working on the code proper, I have a screen session split
> to a ghci session and a vim session editing the file. The ghci sits
> in the base directory of the projects (where the _darcs folder is)
> and has the files I'm working on loaded. I edit, ^a-tab to ghci,
> reload, flip back, fix errors, repeat till it loads. After that, I
> run a few tests to make sure the program does what I think it does,
> if not, I fix it, then back to adding new functionality.
>
> I hope this is what you wanted to know. Towards the point where I'm
> going to release a version, I substitute the ghci-business to a
> proper test harness/cabal build to make sure it compiles all
> correctly.
>
> /Joe
>
>
> On Sep 21, 2009, at 5:35 PM, Tom Doris wrote:
>
> Hi
> I'd like to know what the typical edit-compile-test loop looks like
> with the Haskell platform; that is, in C++ this would be edit, run
> make to compile everything in the project into libraries and
> executables, then run an executable test suite. I'm confused as to
> how people work on larger projects in Haskell - do you work on a
> single module and load it into ghci to test as you develop, then
> compile the entire package and run a test suite? Or do you generally
> only use ghci for prototyping and not when in the middle of proper
> development? Or do you compile the package and load that into ghci?
> I'd like to know as I'm starting to work on patches for some hackage
> packages which have proper cabal builds etc., and want to follow the
> correct (and efficient!) convention.
> Thanks
> Tom
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
------------------------------
Message: 2
Date: Wed, 23 Sep 2009 15:03:03 -0700 (PDT)
From: "Michael Mossey" <[email protected]>
Subject: [Haskell-beginners] StateT, list monad
To: "Haskell Beginners" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain;charset=iso-8859-1
Trying to understand Douglas Auclair's article
"MonadPlus - What a super monad!" here
<http://www.haskell.org/sitewiki/images/6/6a/TMR-Issue11.pdf>
Defines
splits :: Eq a => [a] -> [(a,[a])]
splits list = do x <- list
return (x, delete x list)
choose :: Eq a => StateT [a] [] a
choose = StateT (\s -> splits s)
I'm trying to understand what "StateT [a] [] a" means:
I wrote
t1 :: StateT [Int] [] [Int]
t1 = do
s <- get
return s
That compiles. Then I tried to write
t2 :: StateT [Int] [] [Int]
t2 = do
x <- [1,2,3]
s <- get
return (x:s)
I thought this would be fine because [1,2,3] is an example of a list monad.
But I get
"Can't match expected type StateT [Int] [] t
against inferred type [a]"
------------------------------
Message: 3
Date: Thu, 24 Sep 2009 00:36:09 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] StateT, list monad
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Am Donnerstag 24 September 2009 00:03:03 schrieb Michael Mossey:
> Trying to understand Douglas Auclair's article
> "MonadPlus - What a super monad!" here
> <http://www.haskell.org/sitewiki/images/6/6a/TMR-Issue11.pdf>
>
> Defines
>
> splits :: Eq a => [a] -> [(a,[a])]
> splits list = do x <- list
> return (x, delete x list)
>
> choose :: Eq a => StateT [a] [] a
> choose = StateT (\s -> splits s)
>
> I'm trying to understand what "StateT [a] [] a" means:
StateT stateType innerMonad resultType
The state is a list of a, the inner monad is the list monad, apart from the
newtype
wrapper, it's
[a] -> [(a,[a])]
>
> I wrote
>
> t1 :: StateT [Int] [] [Int]
> t1 = do
> s <- get
> return s
>
> That compiles. Then I tried to write
>
> t2 :: StateT [Int] [] [Int]
> t2 = do
> x <- [1,2,3]
> s <- get
> return (x:s)
>
> I thought this would be fine because [1,2,3] is an example of a list monad.
Within one do-block, you can use only one monad.
do x <- action1
y <- action2
return (f x y)
desugars into
action1 >>= (\x -> (action2 >>= (\y -> (return (f x y)))))
(I used more parentheses than necessary to make the associativity clear, with
less
clutter, it's
action1 >>= \x -> action2 >>= \y -> return (f x y)
.)
The type of (>>=) is
(>>=) :: Monad m => m a -> (a -> m b) -> m b
so you can use only one monad in such an expression.
With StateT (most monad transformers, I think), you can achieve what you want
with
t2 :: StateT [Int] [] [Int]
t2 = do
x <- lift [1,2,3]
s <- get
return (x:s)
'lift' lifts actions in the inner monad to StateT actions.
>
> But I get
>
> "Can't match expected type StateT [Int] [] t
> against inferred type [a]"
>
------------------------------
Message: 4
Date: Thu, 24 Sep 2009 13:12:01 -0500
From: Hong Yang <[email protected]>
Subject: [Haskell-beginners] proxy
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
Hi,
I was using Finance.Quote.Yahoo, but got an error:
user error (openTCPConnection: host lookup failure for "
download.finance.yahoo.com").
I think it is due to I being behind a proxy.
I then imported Network.Browser, ran setProxy, and tried to fetch data using
Finance.Quote.Yahoo.getQuote. I still got the error.
So I suggest the module author incorporate proxy setting inside the module.
Thanks,
Hong
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090924/39755102/attachment-0001.html
------------------------------
Message: 5
Date: Sat, 26 Sep 2009 21:29:49 -0700
From: Joe Van Dyk <[email protected]>
Subject: [Haskell-beginners] Distributing executables
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
How hard is it to distribute a haskell binary that contains a bunch of
libraries embedded in the executable? Is it pretty easy to make a
large statically-linked executable?
--
Joe Van Dyk
http://fixieconsulting.com
------------------------------
Message: 6
Date: Sun, 27 Sep 2009 12:22:50 +0200
From: informationen <[email protected]>
Subject: [Haskell-beginners] Haskell type system
To: [email protected]
Message-ID: <20090927102249.gb4...@debian>
Content-Type: text/plain; charset=us-ascii; format=flowed
Hi,
i am trying to understand the Haskell type system. I thought i understood it
quite well until i encountered the three following exercises. As you can see, i
have the answers already. But i don't understand, why they are correct.
Could anybody tell me a good place where i could learn how to answers these kind
of questions correctly or could give me some explanations, why these answers are
correct?
Any help is highly appreciated.
Kind regards
Chris
Two functions f and g with the following signatures are given:
f :: a -> a
g :: b -> c -> b
A) Give the type of the following expressions:
1) g [False] True ::
2) g [] True ::
3) g (f True) ::
4) g f ::
Answers:
1 [Boolean]
2) [a]
3) c -> Bool
4) c -> (a -> a)1) g f 1
B) Which of the following statements is correct?
2) g (f 1) is type correct
3) g . (f 1) is type correct
4) g . f 1 is type correct
5) (g . f) 1 is type correct
6) none of the expressions is correct
Answers:
1,2 and 5 are correct.
C) A function h is given as: h p x = p (f x). Which of the following
statements is correct.
1) h :: a -> b -> a -> b
2) h :: (a -> a) -> a -> a
3) h :: (a -> b) -> a -> b
4) h is equivalent to h' with h' p = p . f
5) h is equivalent to h' with h' p = p f
5) h is equivalent to h' with h' p x = p f x
Answers:
(I am not sure, if i remember correctly, but 3) and 4) should be
correct.)
------------------------------
Message: 7
Date: Sun, 27 Sep 2009 14:50:53 +0200
From: Peter Verswyvelen <[email protected]>
Subject: Re: [Haskell-beginners] Haskell type system
To: informationen <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Which parts would like explanations for? All of them?
On Sun, Sep 27, 2009 at 12:22 PM, informationen <[email protected]>wrote:
> Hi,
>
> i am trying to understand the Haskell type system. I thought i understood
> it
> quite well until i encountered the three following exercises. As you can
> see, i
> have the answers already. But i don't understand, why they are correct.
>
> Could anybody tell me a good place where i could learn how to answers these
> kind
> of questions correctly or could give me some explanations, why these
> answers are
> correct?
>
> Any help is highly appreciated.
>
> Kind regards
>
> Chris
> Two functions f and g with the following signatures are given:
> f :: a -> a
> g :: b -> c -> b
>
> A) Give the type of the following expressions:
>
> 1) g [False] True :: 2) g [] True :: 3) g (f True) :: 4) g f
> ::
> Answers:
>
> 1 [Boolean] 2) [a] 3) c -> Bool
> 4) c -> (a -> a)1) g f 1
> B) Which of the following statements is correct?
>
> 2) g (f 1) is type correct
> 3) g . (f 1) is type correct
> 4) g . f 1 is type correct
> 5) (g . f) 1 is type correct
> 6) none of the expressions is correct
>
> Answers:
> 1,2 and 5 are correct.
>
> C) A function h is given as: h p x = p (f x). Which of the following
> statements is correct.
>
> 1) h :: a -> b -> a -> b
> 2) h :: (a -> a) -> a -> a
> 3) h :: (a -> b) -> a -> b
> 4) h is equivalent to h' with h' p = p . f
> 5) h is equivalent to h' with h' p = p f
> 5) h is equivalent to h' with h' p x = p f x
>
> Answers:
> (I am not sure, if i remember correctly, but 3) and 4) should be
> correct.)
>
>
> _______________________________________________
> 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/20090927/aaa65450/attachment.html
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 15, Issue 16
*****************************************