[Haskell-cafe] Infinite lists in real world programs
Patai Gergely
patai_gergely at fastmail.fm
Thu Dec 23 22:14:30 CET 2010
> fromList :: [a] -> SignalGen (Signal a)
> fromList xs =
> stateful xs tail >>= memo . fmap head
>
> 1) It does what I want, but is it the good way to do it?
Yes, I'd do it the same way, assuming that the input is always an
infinite list (so this version should probably be called
unsafeFromList...). But you can always make a list infinite, just add a
Maybe layer or pad with a default value.
> 2) Since the returned signal may be used in several places and since I
> obtain it through the generic fmap (and not through an Elerea primitive),
> I guessed I had to "memo" it instead of simply using "return". Did I guess
> right?
That's exactly what memo is needed for, yes. However, whether it is
worth the overhead in such a simple case (after all, head is essentially
just a single dereferencing step) should be determined by profiling.
> 3) Concerning the functionnality added by the Param implementation, I
> have
> the impression that the same can be achieved through the use of an
> external
> signal in Simple (*). Am I right?
Yes, the two are equally expressive. The difference is the way you
access the signals. In the case of Param, you get a globally accessible
signal that you don't need to pass around explicitly, just retrieve with
'input' wherever you want. This might be useful when there's some
ubiquitous piece of information that you need practically everywhere,
e.g. real time for a simulation.
Gergely
--
http://www.fastmail.fm - Does exactly what it says on the tin
More information about the Haskell-Cafe
mailing list