[Haskell-beginners] Simpler than lifting

Adrian May adrian.alexander.may at gmail.com
Tue Mar 19 04:59:33 CET 2013


So function application itself is the functor, i.e., the box-like thing,
right? Lifting a function of values to work on boxes containing those
values corresponds with lifting a function of values to work on functions
yielding those values. Right? In which case, fishing something out of the
box corresponds with applying the function. Why not? With record notation
you use a function to fish out a field anyway. That's very interesting.

Now I have this:

type Amount = Float
type Moment = Day -- from Data.Time.Calendar
data Period = Period Moment Moment
type Flowfunc = Period -> Amount
f0 = const 0

-- Add and subtract flowfuncs
infixl 6 ~+, ~-
(~+), (~-) :: Flowfunc -> Flowfunc -> Flowfunc
f ~+ g = (+) <$> f <*> g
f ~- g = (-) <$> f <*> g

But here I still seem to be being naive again...

-- Multiply flowfunc by a float
infixl 7 ~*
(~*) :: Float -> Flowfunc -> Flowfunc
f ~* n = \p -> n * (f p)
-- or with the params the other way around

I guess I could write:

f ~* n = (*) <$> f <*> const n

but it seems clunky. Should it be a monad?

How about:

-- Sum a list of them
sumf :: [Flowfunc] -> Flowfunc
sumf l = foldl (~+) f0 l

TIA,
Adrian.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130319/fd157ed8/attachment.htm>


More information about the Beginners mailing list