[Haskell-cafe] Do all "fromList" functions redirect to List operations?

martin martin.drautzburg at web.de
Tue Apr 14 22:09:39 UTC 2015

Hello all,

I have a datatype like this:

data Time = DPast | T Integer deriving (Eq, Show)

data Temporal a = Temporal {
            at :: Time -> (a, Maybe Time)

and I wrote a fromList function to create one. The fromList function implements it own "at" function and wraps it in a
Temporal. IIUC, this means that whenever I invoke "at" on a Temporal created from a List I actually operate on that List.

Alternatively I can directly create a Temporal as in

exNat = Temporal f
            f DPast = (0, Just $ T 1)
            f (T t) = (t, Just $ T $ t+1)

whose "at" function is a lot faster.

Do all "fromList" functions behave this way, i.e. they redirect operations on the new type to List operations?

Is there a way to make a Temporal, created via fromList "forget" its List heritage?

More information about the Haskell-Cafe mailing list