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: Is there a (^) function for exponents other than
integral? (Tom Davie)
2. Re: Global variable question (Joe Van Dyk)
3. Re: Is there a (^) function for exponents other than
integral? (Darrin Thompson)
4. Re: Global variable question (John Velman)
5. Re: Global variable question (Joe Van Dyk)
6. Problem installing graphalyze with Cabal (John Velman)
7. Re: Problem installing graphalyze with Cabal (Henk-Jan van Tuyl)
8. Interpreting profiling results (Patrick LeBoutillier)
----------------------------------------------------------------------
Message: 1
Date: Thu, 31 Dec 2009 16:20:03 +0000
From: Tom Davie <[email protected]>
Subject: Re: [Haskell-beginners] Is there a (^) function for exponents
other than integral?
To: Ken Overton <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
(**)
A good place to start on things like this is Hoogle:
http://www.haskell.org/hoogle
Bob
On Thu, Dec 31, 2009 at 4:05 PM, Ken Overton <[email protected]> wrote:
> Sorry if this is from a faq list somewhere, I've been looking through the
> more common locations/libs and have been unable to find a way to raise
> numbers to a fractional exponent. Can someone help me to find such a
> function in haskell?
>
> Thanks,
>
> -- kov
>
> _______________________________________________
> 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/20091231/09bb9047/attachment-0001.html
------------------------------
Message: 2
Date: Thu, 31 Dec 2009 09:37:10 -0800
From: Joe Van Dyk <[email protected]>
Subject: Re: [Haskell-beginners] Global variable question
Cc: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Wed, Dec 30, 2009 at 6:05 PM, Edward Z. Yang <[email protected]> wrote:
> Excerpts from Joe Van Dyk's message of Wed Dec 30 20:49:12 -0500 2009:
>> What's the appropriate way to write this in Haskell?
>
> Hi Joe,
>
> The Ticker class is an example of stateful computation, which we try
> to avoid in Haskell. Â What are you really trying to do?
>
> * If you a number, and you want to add to it, (+1) works
> Â plenty well.
>
> * If you are going to be making ticks, but you don't care about
> Â reading the ticks until the end of the computation, the Writer monad
> Â is of interest.
>
> * If you need to update the tick count and read it, the State
> Â monad is a good bet.
>
> * If you're interested in curiosities from imperative land, STRef, IORef and
> Â other similar creatures may be helpful.
It's like haskell is on a personal vendetta against me to make me feel dumb.
--
Joe Van Dyk
http://fixieconsulting.com
------------------------------
Message: 3
Date: Thu, 31 Dec 2009 12:44:13 -0500
From: Darrin Thompson <[email protected]>
Subject: Re: [Haskell-beginners] Is there a (^) function for exponents
other than integral?
To: Ken Overton <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On Thu, Dec 31, 2009 at 11:05 AM, Ken Overton <[email protected]> wrote:
> Sorry if this is from a faq list somewhere, I've been looking through the
> more common locations/libs and have been unable to find a way to raise
> numbers to a fractional exponent. Can someone help me to find such a
> function in haskell?
>
(**) is in the Prelude, no?
--
Darrin
------------------------------
Message: 4
Date: Thu, 31 Dec 2009 15:38:00 -0800
From: John Velman <[email protected]>
Subject: Re: [Haskell-beginners] Global variable question
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-1
On Thu, Dec 31, 2009 at 09:37:10AM -0800, Joe Van Dyk wrote:
> On Wed, Dec 30, 2009 at 6:05 PM, Edward Z. Yang <[email protected]> wrote:
> > Excerpts from Joe Van Dyk's message of Wed Dec 30 20:49:12 -0500 2009:
> >> What's the appropriate way to write this in Haskell?
> >
> > Hi Joe,
> >
> > The Ticker class is an example of stateful computation, which we try
> > to avoid in Haskell. What are you really trying to do?
> >
> > * If you a number, and you want to add to it, (+1) works
> > plenty well.
> >
> > * If you are going to be making ticks, but you don't care about
> > reading the ticks until the end of the computation, the Writer monad
> > is of interest.
> >
> > * If you need to update the tick count and read it, the State
> > monad is a good bet.
> >
> > * If you're interested in curiosities from imperative land, STRef, IORef and
> > other similar creatures may be helpful.
>
> It's like haskell is on a personal vendetta against me to make me feel dumb.
It's not personal.
John Velman.
>
>
> --
> Joe Van Dyk
> http://fixieconsulting.com
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 5
Date: Thu, 31 Dec 2009 15:43:33 -0800
From: Joe Van Dyk <[email protected]>
Subject: Re: [Haskell-beginners] Global variable question
To: John Velman <[email protected]>, [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Thu, Dec 31, 2009 at 3:38 PM, John Velman <[email protected]> wrote:
> On Thu, Dec 31, 2009 at 09:37:10AM -0800, Joe Van Dyk wrote:
>> On Wed, Dec 30, 2009 at 6:05 PM, Edward Z. Yang <[email protected]> wrote:
>> > Excerpts from Joe Van Dyk's message of Wed Dec 30 20:49:12 -0500 2009:
>> >> What's the appropriate way to write this in Haskell?
>> >
>> > Hi Joe,
>> >
>> > The Ticker class is an example of stateful computation, which we try
>> > to avoid in Haskell. Â What are you really trying to do?
>> >
>> > * If you a number, and you want to add to it, (+1) works
>> > Â plenty well.
>> >
>> > * If you are going to be making ticks, but you don't care about
>> > Â reading the ticks until the end of the computation, the Writer monad
>> > Â is of interest.
>> >
>> > * If you need to update the tick count and read it, the State
>> > Â monad is a good bet.
>> >
>> > * If you're interested in curiosities from imperative land, STRef, IORef
>> > and
>> > Â other similar creatures may be helpful.
>>
>> It's like haskell is on a personal vendetta against me to make me feel dumb.
>
>
> It's not personal.
Feels like it though. :(
------------------------------
Message: 6
Date: Thu, 31 Dec 2009 20:08:52 -0800
From: John Velman <[email protected]>
Subject: [Haskell-beginners] Problem installing graphalyze with Cabal
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
I have Haskell Platform downloaded and installed today. When I tried to
install graphalyze with cabal install, it had problems with pandoc. To
make a long story fairly short, I downloaded pandoc-1.3 from hackage, and
tried building it "by hand". It says it had missing dependencies of
utf8-string >= 0.3, and zip-archive >=0.1.1.
Tried installing them with cabal, and this worked OK.
Still, pandoc setup says:
jrv:pandoc-1.3 jr$ runhaskell Setup configure
Configuring pandoc-1.3...
Setup: At least the following dependencies are missing:
utf8-string >=0.3, zip-archive >=0.1.1
jrv:pandoc-1.3 jr$ cabal install zip-archive-0.1.1.1
I _finally_ checked ghc-pkg list, and I have, among other things:
/Users/jr/.ghc/i386-darwin-6.10.4/package.conf:
{HOC-1.0}, {HOC-Foundation-1.0}, binary-0.5.0.1, binary-0.5.0.2,
bktrees-0.2.2, darcs-2.3.0, digest-0.0.0.8, graphviz-2999.6.0.0,
hashed-storage-0.3.7, haskeline-0.6.1.6, mmap-0.4.1, pandoc-1.3,
polyparse-1.4, terminfo-0.3.0.2, utf8-string-0.3.5,
utf8-string-0.3.6, zip-archive-0.1.1.1, zip-archive-0.1.1.4,
zlib-0.5.2.0
As you see, I've ended up with two copies each (because of my messing
around before I checked ghc-pkg, I guess). Well, all of them are >= the
dependency requirements, If I understand correctly.
What gives? How do I get rid of the extra copies? (By the way, the HOC
entries are left over from an earlier time, and I'd like to get rid of
those also).
Thanks,
John Velman
------------------------------
Message: 7
Date: Fri, 01 Jan 2010 10:44:14 +0100
From: "Henk-Jan van Tuyl" <[email protected]>
Subject: Re: [Haskell-beginners] Problem installing graphalyze with
Cabal
To: "John Velman" <[email protected]>, "Haskell Beginners"
<[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-15; format=flowed;
delsp=yes
On Fri, 01 Jan 2010 05:08:52 +0100, John Velman <[email protected]> wrote:
> What gives? How do I get rid of the extra copies?
You can unregister packages with commands like:
ghc-pkg unregister binary-0.5.0.1 --user
--
Regards,
Henk-Jan van Tuyl
--
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
--
------------------------------
Message: 8
Date: Fri, 1 Jan 2010 10:39:48 -0500
From: Patrick LeBoutillier <[email protected]>
Subject: [Haskell-beginners] Interpreting profiling results
To: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi,
Firstly, Happy New Year!
Secondly, I've written (and improved using other solutions I've found
on the net) a simple sudoku solver which I'm trying to profile.
Here is the code:
import Array
import List (transpose, nub, (\\))
import Data.List
data Sudoku = Sudoku { unit :: Int, cells :: Array (Int, Int) Int,
holes :: [(Int, Int)] }
cell :: Sudoku -> (Int, Int) -> Int
cell s i = (cells s) ! i
instance Read Sudoku where
readsPrec _ s = [(Sudoku unit cells holes, "")]
where unit = length . words . head . lines $ s
cells = listArray ((1, 1), (unit, unit)) (map read . words $ s)
holes = [ c | c <- indices cells, (cells ! c) == 0]
instance Show Sudoku where
show s = unlines [unwords [show $ cell s (x,y) | x <- [1 .. unit s]]
| y <- [1 .. unit s]]
genNums :: Sudoku -> (Int, Int) -> [Int]
genNums s c@(i,j) = ([1 .. u] \\) . nub $ used
where
used = (row s u i j) ++ (col s u i j) ++ (square s sq u i j)
u = unit s
sq = truncate . sqrt . fromIntegral $ u
row s u i j = [cell s (i, y) | y <- [1 .. u]]
col s u i j = [cell s (x, j) | x <- [1 .. u]]
square s sq u i j = [cell s (x, y) | y <- [1 .. u], x <- [1 .. u], f x i, f y j]
where f a b = div (a-1) sq == div (b-1) sq
solve :: Sudoku -> [Sudoku]
solve s =
case holes s of
[] -> [s]
(h:hs) -> do
n <- genNums s h
let s' = Sudoku (unit s) ((cells s) // [(h, n)]) hs
solve s'
main = print . head . solve . read =<< getContents
When I compile as such:
$ ghc -O2 --make Sudoku.hs -prof -auto-all -caf-all -fforce-recomp
and run it on the following puzzle:
0 2 3 4
3 4 1 0
2 1 4 0
0 3 2 1
I get the following profiling report:
Fri Jan 1 10:34 2010 Time and Allocation Profiling Report (Final)
Sudoku +RTS -p -RTS
total time = 0.00 secs (0 ticks @ 20 ms)
total alloc = 165,728 bytes (excludes profiling overheads)
COST CENTRE MODULE %time %alloc
CAF GHC.Handle 0.0 10.7
CAF Text.Read.Lex 0.0 2.1
CAF GHC.Read 0.0 1.2
square Main 0.0 2.8
solve Main 0.0 1.3
show_aVx Main 0.0 3.7
readsPrec_aYF Main 0.0 60.6
main Main 0.0 9.6
genNums Main 0.0 5.0
cell Main 0.0 1.2
individual inherited
COST CENTRE MODULE
no. entries %time %alloc %time %alloc
MAIN MAIN
1 0 0.0 0.3 0.0 100.0
main Main
186 1 0.0 9.6 0.0 85.6
show_aVx Main
196 2 0.0 3.7 0.0 3.7
cell Main
197 16 0.0 0.0 0.0 0.0
solve Main
188 5 0.0 1.3 0.0 11.8
genNums Main
189 8 0.0 5.0 0.0 10.4
square Main
194 88 0.0 2.8 0.0 3.2
cell Main
195 16 0.0 0.4 0.0 0.4
col Main
192 4 0.0 0.7 0.0 1.1
cell Main
193 16 0.0 0.4 0.0 0.4
row Main
190 4 0.0 0.7 0.0 1.1
cell Main
191 16 0.0 0.4 0.0 0.4
readsPrec_aYF Main
187 3 0.0 60.6 0.0 60.6
CAF GHC.Read
151 1 0.0 1.2 0.0 1.2
CAF Text.Read.Lex
144 8 0.0 2.1 0.0 2.1
CAF GHC.Handle
128 4 0.0 10.7 0.0 10.7
CAF GHC.Conc
127 1 0.0 0.0 0.0 0.0
Does the column 'entries' represent the number of times the function
was called? If so, I don't understand
how the 'square' function could be called 88 times when it's caller is
only called 8 times. Same thing with
'genNums' (called 8 times, and solve called 5 times)
What am I missing here?
Patrick
--
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 19, Issue 1
****************************************