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: Function nesting (Zbigniew Stanasiuk)
2. Re: testing and the culture of Haskell (Ahn, Ki Yung)
3. Re: Function nesting (Joe Van Dyk)
4. Re: problems using bytestrings (Joe Van Dyk)
5. Re: testing and the culture of Haskell (Heinrich Apfelmus)
6. Re: testing and the culture of Haskell (Heinrich Apfelmus)
7. Brainfuck interpreter stack overflow (Edgar Klerks)
8. Re: Brainfuck interpreter stack overflow (Stephen Tetley)
9. QuickCheck 2 entering infinite loop (Dominic Mulligan)
10. Re: QuickCheck 2 entering infinite loop (Brent Yorgey)
----------------------------------------------------------------------
Message: 1
Date: Thu, 21 Jan 2010 15:38:41 +0000 (UTC)
From: Zbigniew Stanasiuk <[email protected]>
Subject: [Haskell-beginners] Re: Function nesting
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
>Daniel Fischer <daniel.is.fischer <at> web.de> writes:
>
> foldl' (\z x -> (x*z) `mod` m) 1 [1 .. 5]
Very clever. Thanks a lot. Need to study strict versions of fold.
Zbig
------------------------------
Message: 2
Date: Thu, 21 Jan 2010 15:30:50 -0800
From: "Ahn, Ki Yung" <[email protected]>
Subject: [Haskell-beginners] Re: testing and the culture of Haskell
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
Michael Easter ì´ ê¸:
>
> Q: Note that TDD and "writing tests" are different things. With respect
> to "writing tests", I know
> that HUnit exists and that RWH has a chapter on quality assurance.
>
> Given that, I'd like to know: how widely is HUnit used? If you were to
> start a new Haskell project, would you
> include HUnit (a) immediately (b) eventually (c) maybe (d) another
> adjective ?
Don't forget about QuickCheck which allows us property based
automatically generated random testing. With QuickCheck, one can
practice much more powerful form of TDD, and this is a already a common
practice in Haskell development. QuickCheck works well with pure
functions, and HUnit is more for the IO related actions.
------------------------------
Message: 3
Date: Thu, 21 Jan 2010 18:28:52 -0800
From: Joe Van Dyk <[email protected]>
Subject: Re: [Haskell-beginners] Function nesting
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Thu, Jan 21, 2010 at 6:55 AM, Daniel Fischer
<[email protected]> wrote:
> Am Donnerstag 21 Januar 2010 15:02:11 schrieb Zbigniew Stanasiuk:
>> Hi all,
>>
>> I've just started learning Haskell and I have no idea how to nest
>> function in following structure:
>> Mod(5*Mod(4*Mod(3*Mod(2*Mod(1, m), m), m), m), m) ... etc.
>> Could someone help me.
>
> Instead of func(a,b), write func a b. Arguments which are compund
> expressions themselves must be parenthesized, so
>
> mod (5*mod (4*mod (3*mod (2*mod 1 m) m) m) m) m
>
> But that is completely unreadable.
>
> foldl' (\z x -> (x*z) `mod` m) 1 [1 .. 5]
To the untrained eye, the first version contains a lot less weird
syntax. You only have to know what mod does, and how parenthesis
work, both of which you learn in the third grade or so.
--
Joe Van Dyk
http://fixieconsulting.com
------------------------------
Message: 4
Date: Thu, 21 Jan 2010 19:17:15 -0800
From: Joe Van Dyk <[email protected]>
Subject: Re: [Haskell-beginners] problems using bytestrings
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Tue, Jan 19, 2010 at 2:11 PM, Daniel Fischer
<[email protected]> wrote:
> Am Dienstag 19 Januar 2010 22:34:41 schrieb Joe Van Dyk:
>>
>> Thanks for the response. Â I was getting confused -- I'm used to
>> thinking about a String as being its own type, instead of being an
>> array of chars.
>
> Lists are NOT arrays.
>
> If it was not just loose language on your side, learn the distinction.
> List indexing (list !! k) is O(min k (length list)), array indexing is
> O(1).
> An array knows its size (resp. it can easily be calculated from the known
> bounds), a list does not. length list is O(length list).
>
> If you're not aware of the differences, sooner rather than later, you'll
> get bitten by a gigantic performance bug.
Whoops, yes, I know that -- I'm just used to languages where it's not
as big a deal. :D
Joe
------------------------------
Message: 5
Date: Fri, 22 Jan 2010 11:31:53 +0100
From: Heinrich Apfelmus <[email protected]>
Subject: [Haskell-beginners] Re: testing and the culture of Haskell
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8
Isaac Dupree wrote:
> Heinrich Apfelmus wrote:
>> However, in a sense, one can interpret the pure in purely functional as
>> a property of the type constructor (->) , i.e. a function of type (a ->
>> b) is guaranteed to not have side effects. In this light, ML and Scheme
>> are lacking a very important type: they only have functions with side
>> effects.
>
>> Or more precisely, their type system does not distinguish
>> between functions with and without side effects.
>
> that's not actually more precise! Haskell doesn't entirely do that
> either. consider:
> f :: Int -> IO Int
> f x = return (x + 1)
> No side effects! But other ->IO typed values do yield side-effects.
>
> It is exactly as if ML and Scheme contain only the type of (->) composed
> with IO. (Well, actually Scheme is dynamically typed so it's a bit
> silly to say so..) (and Scheme allows functions with zero arguments,
> which are different from its non-side-effecting values.. not sure about ML)
Yes, "distinguish" in the sense of "optional distinction by annotation"
instead of "automatically detect whether a function has side effects or
not".
(By the way, in a sense it is possible to detect that f has no side
effects. Namely, it's most general type is polymorphic in the monad:
f :: Monad m => Int -> m Int
)
This is much like Java lacking (having lacked?) types whose values
cannot be null , compared to a vs Maybe a in Haskell.
Regards,
Heinrich Apfelmus
--
http://apfelmus.nfshost.com
------------------------------
Message: 6
Date: Fri, 22 Jan 2010 11:37:12 +0100
From: Heinrich Apfelmus <[email protected]>
Subject: [Haskell-beginners] Re: testing and the culture of Haskell
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8
David Virebayre wrote:
> Stephen Blackheath wrote:
>>
>> All Haskell functions are pure without exception. For example:
>
>
> Back to IO. What exactly would be the representation of an IO action,
> if not an abstract notion ? Hopefully that is optimised out by the
> compiler. Indeed, If I look at the compiled output of a simple
> program, it looks to me like the effects are executed within the
> function, and no special structure is returned.
Sure, it's an abstraction, which means that the compiler is free to
optimize it ruthlessly.
But you are also free to implement it differently, like for the purpose
of testing:
Swierstra und Altenkirch. Beauty in the beast.
http://www.cse.chalmers.se/~wouter/Publications/BeautyInTheBeast.pdf
Regards,
Heinrich Apfelmus
--
http://apfelmus.nfshost.com
------------------------------
Message: 7
Date: Fri, 22 Jan 2010 14:33:27 +0100
From: Edgar Klerks <[email protected]>
Subject: [Haskell-beginners] Brainfuck interpreter stack overflow
To: [email protected]
Message-ID: <1264167207.20634.4.ca...@edgar-desktop>
Content-Type: text/plain; charset="UTF-8"
Thanks for your help Stephen and Daniel. The interpreter now doesn't
show any stackoverflows anymore. By using the profiler, I identified
some problems. The State Monad seemed to cause a memory leak. It also
made the interpreter run slow. I removed it, because it isn't neccesary.
I also used Immutable Arrays to store the instructions in, which seemed
to speed it also up. I made the code more functional and the evaluation
loop tail-recursive, which helped a lot.
I am now testing different storage models for the data tape. I now use
Data.Map, but Data.Zipper.List maybe more appropiate.
I didn't know about the profiler and I am suprised it is such a big
help. I never used one before.
Best Wishes,
Edgar
------------------------------
Message: 8
Date: Fri, 22 Jan 2010 15:27:25 +0000
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Brainfuck interpreter stack overflow
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi Edgar
You might want to look at Data.Sequence...
The transform function in your original code did both a cons (add to
the front) and an append / snoc (add one to the end).
transform :: BF -> [BF]
transform (Loop bs) = Jmpz (2 + lengthbs bs) : (bs >>= transform) -- cons
++ [Jmpb (1 + lengthbs bs)] --snoc / append
transform a = [a]
snoc-ing is expensive on standard lists because you have to implement
it as an appending a singleton list (which you did). Append performs a
full traversal of the first list - here is the implementation copied
from the GHC's libraries:
(++) :: [a] -> [a] -> [a]
(++) [] ys = ys
(++) (x:xs) ys = x : xs ++ ys
In contrast, Data.Sequence has cheap operations for cons (<|), snoc
(|>) and append (><).
Best wishes
Stephen
------------------------------
Message: 9
Date: Thu, 21 Jan 2010 22:05:20 +0000
From: Dominic Mulligan <[email protected]>
Subject: [Haskell-beginners] QuickCheck 2 entering infinite loop
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Dear all,
I'm trying to work out how to use QuickCheck 2 (installed via apt-get
from the Ubuntu repositories) and in the process keep managing to get
the quickCheck function (called under GHCi 6.10.4) to enter what appears
to be an infinite loop. Evidently, I'm doing something wrong ...
Here's the problem: I have a module for types, and it exports a datatype
called "Type". I make this an instance of Arbitrary, like so:
instance (Eq a, Arbitrary a) => Arbitrary (Type a) where
arbitrary = oneof [
liftM tyVar arbitrary,
liftM2 tyCon arbitrary arbitrary]
Here, tyVar and tyCon are two functions injecting into Types.
I then write two silly properties to test whether this works. The first
property:
prop_InjectTypeVarFreeVar var =
(freeTypeVars . tyVar) var == [tyVar var]
Works fine. A call to quickCheck gives me the familiar "100 tests
passed" message. The second property:
prop_InjectTypeConFreeVars args =
(freeTypeVars . (tyCon "Fun")) args == (concatMap freeTypeVars args)
Sends quickCheck into an infinite loop of some sort. It manages to get
through 5-6 tests before GHCi is brought to its knees. Before I go
crazy, can anybody explain what I'm doing wrong?
Many thanks in advance,
Dominic
------------------------------
Message: 10
Date: Fri, 22 Jan 2010 11:20:27 -0500
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] QuickCheck 2 entering infinite loop
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Thu, Jan 21, 2010 at 10:05:20PM +0000, Dominic Mulligan wrote:
> The second property:
>
> prop_InjectTypeConFreeVars args =
> (freeTypeVars . (tyCon "Fun")) args == (concatMap freeTypeVars args)
>
> Sends quickCheck into an infinite loop of some sort. It manages to get
> through 5-6 tests before GHCi is brought to its knees. Before I go crazy,
> can anybody explain what I'm doing wrong?
What type is 'args'? Sounds to me more like a combinatorial explosion
of some sort rather than an actual infinite loop.
-Brent
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 19, Issue 19
*****************************************