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: Sandbox Confusion (Britt Anderson)
2. Re: Sandbox Confusion (Karolis Velicka)
3. Re: Sandbox Confusion (Bob Ippolito)
4. Disappointing thought on Haskell -- a simple space leak on
"insert" is hard bug to catch (Dimitri DeFigueiredo)
5. Re: Disappointing thought on Haskell -- a simple space leak
on "insert" is hard bug to catch (KC)
6. Re: Disappointing thought on Haskell -- a simple space leak
on "insert" is hard bug to catch (Mateusz Kowalczyk)
----------------------------------------------------------------------
Message: 1
Date: Fri, 15 Aug 2014 08:06:33 -0400
From: Britt Anderson <[email protected]>
To: <[email protected]>
Subject: Re: [Haskell-beginners] Sandbox Confusion
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
This works if one removes the -threaded option
e.g. cabal exec ghc site.hs
Is there a way to make cabal exec accept ghc options?
--Britt
> Message-ID:
> <cakfcl4v0cntkl6dvxe0yh2cgf6jweehauqk2hev3hctz26j...@mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> On Thu, Aug 14, 2014 at 8:13 PM, Britt Anderson <[email protected]> wrote:
>
> > cabal exec hakyll-init my-site
> > and this works, and I
> > cd ./my-site
> > but the next step specified in the tutorial I can't figure out how to work.
> > It is:
> > ghc --make -threaded site.hs
> >
> > It fails because it cannot find the Hakyll module to import.
> >
> > I am hoping to learn what the proper command would be in a sandbox
> > environment, and
>
>
> You already used it once: put `cabal exec` in front. (Also, you no longer
> need `--make` in current versions of ghc.)
>
> --
> brandon s allbery kf8nh sine nomine associates
> [email protected] [email protected]
> unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> <http://www.haskell.org/pipermail/beginners/attachments/20140814/b8db72b9/attachment-0001.html>
------------------------------
Message: 2
Date: Fri, 15 Aug 2014 14:46:38 +0100
From: Karolis Velicka <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Sandbox Confusion
Message-ID:
<canxl2l4ahg3-pymupntdqt2hawlsr_xhoxog5v2whh0_pho...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Hi. What you can do is run
cabal exec bash
and then simply use `ghc -threaded site.hs` or any other command - the
shell you'd launch with `cabal exec bash` will have the libraries from
your sandbox in its environment.
Best wishes,
Karl (Karolis) Velicka
On 15 August 2014 13:06, Britt Anderson <[email protected]> wrote:
> This works if one removes the -threaded option
> e.g. cabal exec ghc site.hs
>
> Is there a way to make cabal exec accept ghc options?
>
> --Britt
>
>> Message-ID:
>> <cakfcl4v0cntkl6dvxe0yh2cgf6jweehauqk2hev3hctz26j...@mail.gmail.com>
>> Content-Type: text/plain; charset="utf-8"
>>
>> On Thu, Aug 14, 2014 at 8:13 PM, Britt Anderson <[email protected]> wrote:
>>
>> > cabal exec hakyll-init my-site
>> > and this works, and I
>> > cd ./my-site
>> > but the next step specified in the tutorial I can't figure out how to work.
>> > It is:
>> > ghc --make -threaded site.hs
>> >
>> > It fails because it cannot find the Hakyll module to import.
>> >
>> > I am hoping to learn what the proper command would be in a sandbox
>> > environment, and
>>
>>
>> You already used it once: put `cabal exec` in front. (Also, you no longer
>> need `--make` in current versions of ghc.)
>>
>> --
>> brandon s allbery kf8nh sine nomine associates
>> [email protected] [email protected]
>> unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL:
>> <http://www.haskell.org/pipermail/beginners/attachments/20140814/b8db72b9/attachment-0001.html>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 3
Date: Fri, 15 Aug 2014 11:42:52 -0700
From: Bob Ippolito <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Sandbox Confusion
Message-ID:
<CACwMPm9RCo-aW3FnZxwEvAFwG2hH4NYnoAz2QacAty0=gzr...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Fri, Aug 15, 2014 at 6:46 AM, Karolis Velicka <[email protected]>
wrote:
> Hi. What you can do is run
>
> cabal exec bash
>
>
$ cabal exec --help
Usage: cabal exec [FLAGS] COMMAND [-- [ARGS...]]
according to the Usage, you should probably do this instead:
$ cabal exec ghc -- -threaded site.hs
It's a common unix convention to have `--` separate flags from arguments,
for example:
$ echo '--not-a-flag' | grep --not-a-flag
grep: unrecognized option `--not-a-flag'
$ echo '--not-a-flag' | grep -- --not-a-flag
--not-a-flag
-bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140815/45864774/attachment-0001.html>
------------------------------
Message: 4
Date: Fri, 15 Aug 2014 18:15:16 -0600
From: Dimitri DeFigueiredo <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Disappointing thought on Haskell -- a
simple space leak on "insert" is hard bug to catch
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Here's a problem I just found with Haskell (and maybe functional
programming)
that I would like to know how to avoid.
Please don't get me wrong. I'm in *LUUV* with Haskell! :-)
Exercise 2.3 of Chris Okasaki's book "Purely Functional Data Structures"
shows that
something as simple as an insert function in a binary tree can cause a space
leak in Haskell. (and other functional languages as well)
Here's a simple tree type:
data Tree a = Empty
| MkTree (Tree a) a (Tree a)
Here's the version of insert with the space leak:
-- ** SPACE LEAK! ** version
-- this version unnecessarily copies the path to the inserted element
even if
-- the same element is already present in the tree.
-- a million insertions of the same element will cause a million trees
-- to exist whereone would suffice.
treeInsert :: Ord a => a -> Tree a -> Tree a
treeInsert e Empty = MkTree Empty e Empty
treeInsert e t@(MkTree a x b) | e > x = MkTree a x (treeInsert e b)
| e < x = MkTree (treeInsert e a) x b
| otherwise = t
Here's a version without the space leak:
treeInsert :: Ord a => a -> Tree a -> Tree a
treeInsert e t = case (treeInsert' e t) of
Nothing -> t
Just x -> x
where
treeInsert' :: Ord a => a -> Tree a -> Maybe (Tree a)
treeInsert' e Empty = return $ MkTree Empty e Empty
treeInsert' e (MkTree a x b) | e > x = do {r <- treeInsert'
e b; return $ MkTree a x r}
| e < x = do {r <- treeInsert'
e a; return $ MkTree r x b}
| otherwise = Nothing
This is so tricky that I think it is worth questioning whether Haskell
is helping here.
First, just spotting that the first version leads to a space leak is not
trivial. Second, the fix
is so much uglier than the original version. It is disappointing to have
to write it!
Questions:
1) ** Is there a warning sign that would easily flag this space leak? **
2) Is there a simpler fix?
Cheers,
Dimitri
------------------------------
Message: 5
Date: Fri, 15 Aug 2014 17:48:58 -0700
From: KC <[email protected]>
To: Haskell Beginners <[email protected]>
Subject: Re: [Haskell-beginners] Disappointing thought on Haskell -- a
simple space leak on "insert" is hard bug to catch
Message-ID:
<camlkxymwcnpn5esb8mpmzrck74agve+lo3qdm4fzv_hglob...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Sometimes one wants duplicate keys.
Perhaps findkey might be better.
--
--
Sent from an expensive device which will be obsolete in a few months! :D
Casey
On Aug 15, 2014 5:15 PM, "Dimitri DeFigueiredo" <[email protected]>
wrote:
> Here's a problem I just found with Haskell (and maybe functional
> programming)
> that I would like to know how to avoid.
>
> Please don't get me wrong. I'm in *LUUV* with Haskell! :-)
>
>
> Exercise 2.3 of Chris Okasaki's book "Purely Functional Data Structures"
> shows that
> something as simple as an insert function in a binary tree can cause a
> space
> leak in Haskell. (and other functional languages as well)
>
> Here's a simple tree type:
>
> data Tree a = Empty
> | MkTree (Tree a) a (Tree a)
>
> Here's the version of insert with the space leak:
>
> -- ** SPACE LEAK! ** version
> -- this version unnecessarily copies the path to the inserted element even
> if
> -- the same element is already present in the tree.
> -- a million insertions of the same element will cause a million trees
> -- to exist whereone would suffice.
>
> treeInsert :: Ord a => a -> Tree a -> Tree a
> treeInsert e Empty = MkTree Empty e Empty
> treeInsert e t@(MkTree a x b) | e > x = MkTree a x (treeInsert e b)
> | e < x = MkTree (treeInsert e a) x b
> | otherwise = t
>
> Here's a version without the space leak:
>
> treeInsert :: Ord a => a -> Tree a -> Tree a
> treeInsert e t = case (treeInsert' e t) of
> Nothing -> t
> Just x -> x
> where
> treeInsert' :: Ord a => a -> Tree a -> Maybe (Tree a)
> treeInsert' e Empty = return $ MkTree Empty e Empty
> treeInsert' e (MkTree a x b) | e > x = do {r <- treeInsert' e
> b; return $ MkTree a x r}
> | e < x = do {r <- treeInsert' e
> a; return $ MkTree r x b}
> | otherwise = Nothing
>
>
> This is so tricky that I think it is worth questioning whether Haskell is
> helping here.
> First, just spotting that the first version leads to a space leak is not
> trivial. Second, the fix
> is so much uglier than the original version. It is disappointing to have
> to write it!
>
> Questions:
> 1) ** Is there a warning sign that would easily flag this space leak? **
> 2) Is there a simpler fix?
>
>
> Cheers,
>
>
> Dimitri
>
>
>
>
> _______________________________________________
> 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/20140815/d8726451/attachment-0001.html>
------------------------------
Message: 6
Date: Sat, 16 Aug 2014 05:06:39 +0100
From: Mateusz Kowalczyk <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Disappointing thought on Haskell -- a
simple space leak on "insert" is hard bug to catch
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252
On 08/16/2014 01:15 AM, Dimitri DeFigueiredo wrote:
> Here's a problem I just found with Haskell (and maybe functional
> programming)
> that I would like to know how to avoid.
>
> Please don't get me wrong. I'm in *LUUV* with Haskell! :-)
>
>
> Exercise 2.3 of Chris Okasaki's book "Purely Functional Data Structures"
> shows that
> something as simple as an insert function in a binary tree can cause a space
> leak in Haskell. (and other functional languages as well)
>
> Here's a simple tree type:
>
> data Tree a = Empty
> | MkTree (Tree a) a (Tree a)
>
> Here's the version of insert with the space leak:
>
> -- ** SPACE LEAK! ** version
> -- this version unnecessarily copies the path to the inserted element
> even if
> -- the same element is already present in the tree.
> -- a million insertions of the same element will cause a million trees
> -- to exist whereone would suffice.
>
> treeInsert :: Ord a => a -> Tree a -> Tree a
> treeInsert e Empty = MkTree Empty e Empty
> treeInsert e t@(MkTree a x b) | e > x = MkTree a x (treeInsert e b)
> | e < x = MkTree (treeInsert e a) x b
> | otherwise = t
>
> Here's a version without the space leak:
>
> treeInsert :: Ord a => a -> Tree a -> Tree a
> treeInsert e t = case (treeInsert' e t) of
> Nothing -> t
> Just x -> x
> where
> treeInsert' :: Ord a => a -> Tree a -> Maybe (Tree a)
> treeInsert' e Empty = return $ MkTree Empty e Empty
> treeInsert' e (MkTree a x b) | e > x = do {r <- treeInsert'
> e b; return $ MkTree a x r}
> | e < x = do {r <- treeInsert'
> e a; return $ MkTree r x b}
> | otherwise = Nothing
>
>
> This is so tricky that I think it is worth questioning whether Haskell
> is helping here.
> First, just spotting that the first version leads to a space leak is not
> trivial. Second, the fix
> is so much uglier than the original version. It is disappointing to have
> to write it!
>
> Questions:
> 1) ** Is there a warning sign that would easily flag this space leak? **
Benchmarking and profiling.
> 2) Is there a simpler fix?
I don't know.
>
> Cheers,
>
>
> Dimitri
>
--
Mateusz K.
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 74, Issue 11
*****************************************