It's possible to decouple time from physics, and it's especially easy in Haskell.
The (higher order) function below (lazily) accepts a list of events and yields a function which can give the historical or predicted displacement at any given time.
Note: The events do not have to be in chronological order - this provides a way to deal with lag in networked games.
The lazy nature of Haskell means that if the list of events is infinite (e.g. data from a network socket) then the generated function will give improved accuracy of position (for a given time) as more events are received.
newtype EvTime = T Double
newtype Impulse = I Double
newtype Displacement = D Double
deriving (Eq,Show)
data Event = Ev EvTime Impulse
-- I can't yet figure out how to define or derive (+) for Displacement
plus (D x) (D x') = D (x + x')
-- 'calc' returns a function which calculates displacement at a given time,
-- provided a list of events are provided
calc :: [Event] -> (EvTime -> Displacement)
calc [] = (\ _ -> D 0.0)
calc (Ev (T et) (I i):es) = f
where
f (T t) = if t > et
then -- physics assumes unit mass
D ((t - et) * i) `plus` calc es (T t)
else
calc es (T t)Here's a simple demonstration...
*Main> :load Eventual.hs [1 of 1] Compiling Main ( Eventual.hs, interpreted ) Ok, modules loaded: Main. *Main> let l = [Ev (T 1.0) (I 1.0), Ev (T 4.0) (I 0.5), Ev (T 2.0) (I (-2.0))] *Main> let f = calc l *Main> f (T 0.0) D 0.0 *Main> f (T 0.5) D 0.0 *Main> f (T 1.0) D 0.0 *Main> f (T 1.5) D 0.5 *Main> f (T 2.0) D 1.0 *Main> f (T 2.5) D 0.5 *Main> f (T 3.0) D 0.0 *Main> f (T 3.5) D (-0.5) *Main> f (T 4.0) D (-1.0) *Main> f (T 4.5) D (-1.25) *Main> f (T 5.0) D (-1.5)
Comments
affordable homes in
affordable homes in California
Real Estate | Homes | 3.5% FHA | Mortgage | Houses | 100% VA | Homes For Sale | Realtors | Zero Down USDA | San Mateo Real Estate | Alameda Real Estate | Half Percent Down | Fontana Real Estate | Lodi Real Estate | 203 K FHA | Murrieta Real Estate | Pomona Real Estate | Conventional Loans | Redondo Beach Real Estate | San Clemente Real Estate | Jumbo Loans | Whittier Real Estate | Hawthorne Real Estate | City Down Payment | Riverside House | San Ramon Real Estate | 2yr BK Discharge OK | Tracy Real Estate | West Hollywood Real Estate | <620 FICO with No 12 mo lates | Dana Point Real Estate | Garden Grove Real Estate | 620+ FICO Ok | Los Altos Real Estate | Redwood City Real Estate | 6% Seller Credit OK | Tustin Real Estate | Apple Valley Real Estate | 30 Yr Fixed | Downey Real Estate | Fairfield House | 15 Yr Fixed | Hemet Real Estate | Los Gatos Real Estate | 20 Yr Fixed | Manhattan Beach Real Estate | Menlo Park Real Estate | 5 Yr Adjustable | Aliso Viejo Real Estate | Buena Park Real Estate | 7 Yr Adjustable | Chatsworth Real Estate | Cupertino Real Estate | 10 Yr Adjustable
Abercrombie
High Waist Straight-leg pants outfit stunted jacket, showing slender eye-catching position, pertinent mixture of units Cheap Abercrombie and Fitch Outerwears Cheap Abercrombie and Fitch Outerwears discount Abercrombie and Fitch Outerwears discount Abercrombie and Fitch Outerwears Abercrombie and Fitch Outerwears sale Abercrombie and Fitch Outerwears sale buy Abercrombie and Fitch Outerwears buy Abercrombie and Fitch Outerwears Cheap Abercrombie Fitch Outerwears Cheap Abercrombie Fitch Outerwears discount Abercrombie Fitch Outerwears discount Abercrombie Fitch Outerwears Abercrombie Fitch Outerwears sale Abercrombie Fitch Outerwears sale buy Abercrombie Fitch Outerwears buy Abercrombie Fitch Outerwears Cheap Abercrombie Outerwears Cheap Abercrombie Outerwears discount Abercrombie Outerwears discount Abercrombie Outerwears Abercrombie Outerwears sale Abercrombie Outerwears sale buy Abercrombie Outerwears at Break; DSquared jeans on The patches, holes, stains a Less.
define or derive (+) for Displacement
I discovered you can do this by adding:
{-# LANGUAGE GeneralizedNewtypeDeriving #-}and then auto derive Num:
And then the line:
Becomes:
Thanks
Thanks, that's just what I was looking for.