Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Re: Better Code (Graham Gill) 2. Re: Better Code (Jeffrey Brown) 3. safe versions of pred and succ? (Graham Gill) ---------------------------------------------------------------------- Message: 1 Date: Fri, 13 Jan 2017 19:09:49 -0500 From: Graham Gill <math.simp...@gmail.com> To: beginners@haskell.org Subject: Re: [Haskell-beginners] Better Code Message-ID: <c6d73828-4958-a3ff-be44-d6543583e...@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Sorry, I mean, "groups together consecutive and equal terms, that occur sequentially". Examples speak louder than general descriptions! On 13-Jan-2017 6:43 PM, Graham Gill wrote: > Here's one that does what you want, doesn't require the list to be > sorted, and groups together consecutive and equal terms: ------------------------------ Message: 2 Date: Fri, 13 Jan 2017 17:14:54 -0800 From: Jeffrey Brown <jeffbrown....@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Better Code Message-ID: <caec4ma29sueehutlu1m4n5zyhcmvzh20kjdbo94ednbghv-...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" You could zip the original list to its own tail. On Fri, Jan 13, 2017 at 4:09 PM, Graham Gill <math.simp...@gmail.com> wrote: > Sorry, I mean, "groups together consecutive and equal terms, that occur > sequentially". Examples speak louder than general descriptions! > > On 13-Jan-2017 6:43 PM, Graham Gill wrote: > >> Here's one that does what you want, doesn't require the list to be >> sorted, and groups together consecutive and equal terms: >> > > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Jeff Brown | Jeffrey Benjamin Brown Website <https://msu.edu/~brown202/> | Facebook <https://www.facebook.com/mejeff.younotjeff> | LinkedIn <https://www.linkedin.com/in/jeffreybenjaminbrown>(spammy, so I often miss messages here) | Github <https://github.com/jeffreybenjaminbrown> -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20170113/62945733/attachment-0001.html> ------------------------------ Message: 3 Date: Sat, 14 Jan 2017 02:35:17 -0500 From: Graham Gill <math.simp...@gmail.com> To: Haskell Beginners <beginners@haskell.org> Subject: [Haskell-beginners] safe versions of pred and succ? Message-ID: <bf28216f-f6b5-2d99-54c5-134acbcfa...@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Suppose I have a function f :: (Enum a) => a -> ... f x ... = ...pred x ... If a is also an instance of Bounded, then I get a runtime error if pred minBound is evaluated during evaluation of f. If I try to protect the use of pred x with a check using minBound, then I have to add a Bounded constraint on type a, which would mean, for example, that I can no longer use f with type Integer. Do I need two different versions of f, one for Bounded a and one for non-Bounded a? Is there a more elegant way to take care of this problem? I don't know much about all of the type magic available in GHC. For example, from another list message, groupConsecutive :: (Enum a,Eq a) => [a] -> [[a]] groupConsecutive = foldr go [] where go x ls@(hd@(y:_):yss) | x == y || x == pred y = (x:hd):yss | otherwise = [x]:ls go x [] = [[x]] > groupConsecutive [1,2,3,7,8,10,11,12] [[1,2,3],[7,8],[10,11,12]] > groupConsecutive ([1,0,1,2]::[Word]) *** Exception: Enum.pred{Word}: tried to take `pred' of minBound In the first go case, if type a is also Bounded, y == minBound and x /= y, then we know already that x /= pred y, we want the guard to fail and that we pass to the otherwise guard to start a new sublist. But how to implement it without making the function unavailable for un-Bounded types? Graham ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 103, Issue 10 ******************************************