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:  Guards problem (Stijn Muylle)
   2. Re:  Guards problem (Magnus Therning)
   3.  recursive 'let' ? (John M. Dlugosz)
   4. Re:  recursive 'let' ? (Karl Voelker)


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

Message: 1
Date: Thu, 10 Apr 2014 14:20:17 +0200
From: Stijn Muylle <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Guards problem
Message-ID:
        <cagvaf9ztsevrecehbqlhtz7ia60rr4nexlm6slg7z+ofmbn...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Found the problem: I had a bug in my implementation (see Marcus' comment).

The solution provided by Dan (using a 2d array) seems better, but right now
I'm just focussing on making it work ;)


On Thu, Apr 10, 2014 at 9:48 AM, Stijn Muylle <[email protected]> wrote:

>
> All,
>
> I ran into a small problem using guards, and I don't really understand
> what I'm doing wrong.
>
> I have this code:
>
> ----------------------------------
> import Data.List.Split
> type Cell = Bool
> data Board = Board [[Cell]] deriving Show
>
> trueList = True : trueList
>
> createBoard :: Int -> Int -> Board
> createBoard x y = Board (chunksOf x (take (x * y) trueList))
>
> getCellAt :: Int -> Int -> Board -> Cell
> getCellAt x y (Board b)
>         | x >= (length b) =  False
>         | y >= (length (b !! 0)) =  False
>         | otherwise     =  (b !! x) !! y
>
> -----------------------------------
>
> When I try to execute this:
>
> getCellAt (-1) 0 $ createBoard 3 3
>
> I get a negative index exception. However, as -1 is smaller than 3 (length
> of the board), I would expect False to be returned.
>
> Am I overlooking something?
>
> Thanks!
> Stijn
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140410/037704f8/attachment-0001.html>

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

Message: 2
Date: Thu, 10 Apr 2014 23:19:16 +0200
From: Magnus Therning <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Guards problem
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

On Thu, Apr 10, 2014 at 02:20:17PM +0200, Stijn Muylle wrote:
> Found the problem: I had a bug in my implementation (see Marcus' comment).

I think that should be "Magnus' comment" ;)

/M

-- 
Magnus Therning                      OpenPGP: 0xAB4DFBA4 
email: [email protected]   jabber: [email protected]
twitter: magthe               http://therning.org/magnus

Heuristic is an algorithm in a clown suit. It?s less predictable, it?s more
fun, and it comes without a 30-day, money-back guarantee.
     -- Steve McConnell, Code Complete 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140410/3487aa6b/attachment-0001.sig>

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

Message: 3
Date: Thu, 10 Apr 2014 19:12:25 -0500
From: "John M. Dlugosz" <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] recursive 'let' ?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed

I understand that the definitions introduced by 'let' can be recursive, even 
mutually 
recursive among several names.  Why would you want to do that?  I saw contrived 
examples, 
and wonder why the authors never show a realistic example.

        let b = f a c
            c = f a b
        in ...

I see that makes sense in light of lazy evaluation: b is really an alias for a 
(recursive) 
function, not a value that needs to find fixed points.

Is this used for common idioms and problem-solving approaches in Haskell?

--John



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

Message: 4
Date: Thu, 10 Apr 2014 23:50:19 -0700
From: Karl Voelker <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] recursive 'let' ?
Message-ID:
        <[email protected]>
Content-Type: text/plain

On Thu, Apr 10, 2014, at 05:12 PM, John M. Dlugosz wrote:
> I understand that the definitions introduced by 'let' can be recursive,
> even mutually 
> recursive among several names.  Why would you want to do that?  I saw
> contrived examples, 
> and wonder why the authors never show a realistic example.
> 
>       let b = f a c
>           c = f a b
>       in ...

I am a bit confused by your question.

I assume you know about the usefulness of recursion in general, and that
your question is only about recursion in the context of a let-binding.
But it seems to me that there is nothing particularly special about the
let-binding context, as compared to, for example, the top level of a
module. So what seems different about it to you?

Your code snippet makes me think that perhaps you are specifically
interested in definitions of non-function values. Is that so?

-Karl


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

Subject: Digest Footer

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


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

End of Beginners Digest, Vol 70, Issue 23
*****************************************

Reply via email to