[Haskell-cafe] An ugly zip3 problem..
Michael Feathers
mfeathers at mindspring.com
Sat Mar 22 08:53:58 EDT 2008
One thing that gets me about this solution.. as I was structuring mine I
noticed that I was ending up with types like FilterWindow3 and functions
like lowPass3. Inlining does eliminate them, but I wonder whether there
is a good way to structure the computation generically so that it can be
performed with windows of 5 as well as 3. The cons pattern matching
here would get in the way, and in my original solution, the fact that I
was using tuples got in the way also.
Would Haskell's type system allow you to pass a function of arbitrary
arity, discern its arity, use that information to construct the
appropriate structure for iteration, and then apply it?
Michael
Tillmann Rendel wrote:
>
> by inlining the definition above, this can be given as a four-liner now:
>
> smooth n = (!! n) . iterate f where
> f ds = [(g y z + 2 * y + x) / 4.0 | x:y:z <- tails (head ds : ds)]
> g x [] = x
> g _ (x:_) = x
>
> :-)
>
> Tillmann
>
--
Now Playing: http://www.youtube.com/watch?v=SsnDdq4V8zg
More information about the Haskell-Cafe
mailing list