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:  Solution to problem 17 (99 Haskell problems)?
      (Christopher Reichert)


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

Message: 1
Date: Mon, 08 Dec 2014 08:53:20 -0600
From: Christopher Reichert <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Solution to problem 17 (99 Haskell
        problems)?
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"


On Mon, Dec 08 2014, jean lopes <[email protected]> wrote:
> Hello, I am wondering, is this solution acceptable to the question 17 ? (
> https://www.haskell.org/haskellwiki/99_questions/11_to_20)
>
> code:
> split :: [a] -> Int -> ([a], [a])
> split xs y = fst (mapAccumL (\a b -> (let f = fst a
>                                           s = snd a
>                                           l = length f
>                                       in  if l < y
>                                             then (f ++ [b], s)
>                                             else (f, s ++ [b]), b)) ([],[]) 
> xs)


The example worked for me, so yes! It's a bit hard to read, though.


Stylistically, I would move the the let expressions into a where block
for readability. That would open up a few other pattern matching
opportunities. e.g.


    split :: [a] -> Int -> ([a], [a])
    split xs y = fst (mapAccumL go ([],[]) xs)
      where
        go (f,s) b = if length f < y
                        then ((f ++ [b], s), b)
                        else ((f, s ++ [b]), b)


Cheers,

-Christopher


>
> Also, any inputs are welcome (indentation, misuse of something)
>
> Best regards,
> Jean Lopes
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners

--
Christopher Reichert
irc: creichert
gpg: C81D 18C8 862A 3618 1376  FFA5 6BFC A992 9955 929B
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20141208/b488f839/attachment-0001.sig>

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

Subject: Digest Footer

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


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

End of Beginners Digest, Vol 78, Issue 4
****************************************

Reply via email to