[Haskell-beginners] exercises/examples for streams

Carl Eyeinsky eyeinsky9 at gmail.com
Fri Dec 12 08:40:36 UTC 2014


Hi, Pascal

(and hi, list!)


1. Here is one: define a function that takes two lists, both of which have
elements in growing order (i.e 1,2,3,3,5,9,9,..), and outputs a list with
the type of [Either a a], where a `Left a' would represent an element from
the first list, a `Right a' from the second list. Make it so that the
elements are in order, and also that the lefts preceede the rights.

Example, the inputs of [1,1,3,7,7] and [1,2,3,5,5] would result in [Left 1,
Left 1, Right 1, Right 2, Left 3, Right 3, Right 5, Right 5, Left 7, Left 7]


2. As an extension (not sure if this is too difficult for what you're
looking for): write another function that takes a list-of-lists as input
and outputs the result in tuples, where the first member is the index of
the list (counting from zero), and the second is the value itself.

Example [[1,3],[2,3],[1,3,4]] should result in
[(0,1),(2,1),(1,2),(0,3),(1,3),(2,3),(2,4)]



















On Fri, Dec 12, 2014 at 4:14 AM, Pascal Knodel <pascal.knodel at mail.com>
wrote:
>
> Hello,
>
> I'm preparing for an exam (university level introductory course).
> Functional programming in Haskell is part of it. That includes the
> concept of streams (theoretically infinite list computations).
>
> I have difficulties in solving exercises that ask me to define streams
> for a given problem. Do you know good examples, the difficulty should
> be maybe a little harder than Fibonacci or intersections, but solvable in
> about 5 to 10 minutes. If there are examples from the book "Haskell -
> the craft of functional programming", please don't spoiler, I'm reading
> it parallel to this conversation. Don't give solutions, just problems (5 to
> 10 more will do). Examples, other than integer sequences are welcome.
>
> Pascal
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>


-- 
Carl Eyeinsky
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20141212/ae5315ae/attachment.html>


More information about the Beginners mailing list