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:  Made a video sharing my Haskell workflow and thought
      process while hacking on a library I wrote (Nadir Sampaoli)
   2. Re:  Made a video sharing my Haskell workflow and thought
      process while hacking on a library I wrote (Francesco Ariis)
   3. Re:  Lions, Wolves and Goats (Bob Ippolito)
   4. Re:  Lions, Wolves and Goats (Ben Gamari)


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

Message: 1
Date: Sun, 8 Jun 2014 14:42:40 +0200
From: Nadir Sampaoli <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Made a video sharing my Haskell
        workflow and thought process while hacking on a library I wrote
Message-ID:
        <CAFYwTdQE=pLLk7G1EMDibr1X=_wmazedtryx6t6iz2i4s1q...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Hello,

2014-06-08 9:30 GMT+02:00 Christopher Allen <[email protected]>:
>
> https://www.youtube.com/watch?v=Li6oaO8x2VY
>
> --- Chris

I am just a Haskell beginner/hobbyist; so it comes as a positive
surprise that my workflow isn't much different from what I've seen in
the video.
What I'm not sure of is if the case in study is representative of what
most of Haskell development consist of or if it's just one aspect: I
refer to the fact that the video mostly consisted of writing a binding
to a particular JSON object structure.

I was expecting to see a large use of things like Monad Reader and
State and Transformers and Lenses and stuff I don't understand: did
you try to keep them away from this recording on purpose or they don't
actually come up in real work as often as they seem to do to "an
outside observer" like me?

It was certainly interesting to see how to add type safety for
something which is as far from type safety as you can go (I'm clearly
referring to JS objects :P). This seems an important aspect in Haskell
development: getting into type-safety as soon as possible in these
kinds of translations.

The most important thing about this kind of video, as far as I'm
concerned, is seeing how someone else (and, most importantly, someone
experienced) works. As I said, I'm a hobbyist, so when I play with
Haskell I'm alone 100% of the time and have a hard time seeing where I
could do better and what parts should I focus more.
It must to be said that IRC and blogs are undoubtedly a big help, but
what I, as a beginner, am mostly looking for, is a visual witness of
actual, hands-on workflow process and especially the reasoning that
backs up the act of writing code (and not some made-up examples like
list manipulations et similia).

So, yes, this video was certainly instructive and I'd like to see more!

Thank you,
Nadir


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

Message: 2
Date: Sun, 8 Jun 2014 15:19:56 +0200
From: Francesco Ariis <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Made a video sharing my Haskell
        workflow and thought process while hacking on a library I wrote
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Sun, Jun 08, 2014 at 02:30:12AM -0500, Christopher Allen wrote:
> Not a straw-project, real thing I've been working on. Have gotten good
> feedback so far and was told I should post it here.
> 

Thanks for sharing, I picked up some useful tips from your video (e.g.:
having |-Wall| always on), and apart from that it is always interesting
to see someone writing programs "in the wild".

The quality of the audio bothered me a bit (I can hear white noise in
the background and that muddles your voice).

Hope to see more of these videos!



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

Message: 3
Date: Sun, 8 Jun 2014 12:41: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] Lions, Wolves and Goats
Message-ID:
        <cacwmpm-m4swsywf2qyp92zjzw2h-3evumox2poxa1czvb19...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Here's another approach that more closely models what's going on in the C++
version. I defined an ordNub rather than using nub as nub is O(n^2) as it
only requires Eq.

https://gist.github.com/etrepum/5bfedc8bbe576f89fe09

import qualified Data.Set as S
import Data.List (partition)
import System.Environment (getArgs)

data LWG = LWG { _lion, _wolf, _goat :: {-# UNPACK #-} !Int }
     deriving (Show, Ord, Eq)

lionEatGoat, lionEatWolf, wolfEatGoat :: LWG -> LWG
lionEatGoat (LWG l w g) = LWG (l - 1) (w + 1) (g - 1)
lionEatWolf (LWG l w g) = LWG (l - 1) (w - 1) (g + 1)
wolfEatGoat (LWG l w g) = LWG (l + 1) (w - 1) (g - 1)

stableState :: LWG -> Bool
stableState (LWG l w g) = length (filter (==0) [l, w, g]) >= 2

validState :: LWG -> Bool
validState (LWG l w g) = all (>=0) [l, w, g]

possibleMeals :: LWG -> [LWG]
possibleMeals state =
  filter validState .
  map ($ state) $ [lionEatGoat, lionEatWolf, wolfEatGoat]

ordNub :: Ord a => [a] -> [a]
ordNub = S.toList . S.fromList

endStates :: [LWG] -> [LWG]
endStates states
  | not (null stable)   = stable
  | not (null unstable) = endStates (concatMap possibleMeals unstable)
  | otherwise           = []
  where (stable, unstable) = partition stableState (ordNub states)

main :: IO ()
main = do
  [l, w, g] <- map read `fmap` getArgs
  mapM_ print . endStates $ [LWG l w g]



On Sat, Jun 7, 2014 at 11:33 PM, Francesco Ariis <[email protected]> wrote:

> On Sat, Jun 07, 2014 at 08:04:09PM -0400, Elric wrote:
> > Hi,
> >
> > I came across this article:
> http://unriskinsight.blogspot.co.at/2014/06/fast-functional-goats-lions-and-wolves.html
> > a couple of days ago. This compares performance of solving a problem
> > (which I will get to) using the functional constructs alone in
> > languages like C++11 and Java 8.
> > Since, Haskell is my first foray into FP, I thought I should try
> > solving this in Haskell.
> >
>
> Hello Elric,
>     I gave a go at the problem, managed to get a result (23).
> I attach the .hs file (not my best Haskell, but hopefully clear enough).
>
> The crucial point in my solution lies in this lines:
>
>     carnage :: [Forest] -> [Forest]
>     let wodup = nub aa in
>     -- etc. etc.
>
> Which means after every iteration I call |nub| on my list of possible
> states; nub is a function from |Data.List| and removes duplicate
> elements from a list.
>
> If I omit that nub call, the program doesn't reach a solution (as it
> is computationally quite inefficient). I think that's the problem
> with your versions.
>
> Let me know if this helps
>
>
>
>
>
>
>
> _______________________________________________
> 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/20140608/4579faa7/attachment-0001.html>

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

Message: 4
Date: Sun, 08 Jun 2014 16:52:27 -0400
From: Ben Gamari <[email protected]>
To: Elric <[email protected]>, [email protected]
Subject: Re: [Haskell-beginners] Lions, Wolves and Goats
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

Elric <[email protected]> writes:

> Hi,
> 
> Disclaimer: I have been learning Haskell for a month and there are still 
> several things about this wonderful language I know nothing of, so 
> please bear with me. Also, I apologize for this (somewhat) long mail./
>
...
>
> Below are the two versions of the code I came up with to solve this. 
> Neither of them converge to the 'endStates' even after about 15 minutes. 
> So there is definitely something wrong with what I have done. But after 
> banging my head on the keyboard for more then a day with this, I would 
> appreciate some pointers or help.
>
For one, you don't appear to be removing duplicates from the search set
resulting in a blow-up in your search space.

>
> I thought using the ADT was causing the performance issue and reverted 
> to using a plain 3-termed list which holds [Lion count, Wolf Count, 
> Sheep Count] :: [Int]
>
Your problem here isn't the use of ADTs, it's the use of lists. Why not
instead define a forest as follows?

    data Forest = Forest { wolfs, lions, goats :: !Int }

Note how I used a strictness annotation !Int here to ensure that the
compiler unboxes these members (at least with GHC >= 7.8), which is
almost certainly what you want in this case.

Anyways, I took a quick stab at the problem myself. My approach can be
found here[1]. Performance isn't great (a bit better than Javascript)
but then again the code is pretty much as naive as one could get. I'm
sure things could be improved.

Cheers,

- Ben


[1] https://gist.github.com/anonymous/e4a2ccd8df05255d5ed5
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 472 bytes
Desc: not available
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140608/7cab5c33/attachment-0001.sig>

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

Subject: Digest Footer

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


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

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

Reply via email to