[Haskell-beginners] Lifting Numbers

PATRICK BROWNE patrick.browne at dit.ie
Tue Oct 3 13:07:01 UTC 2017

I am trying to compile, run, and understand the following code from [1].

type Moving v = Time -> v

class Number a where
(+), (-), (*) :: a -> a -> a
sqr, sqrt :: a -> a
sqr a = a * a

instance Number v => Number (Moving v) where
 (+) a b = \t -> (a t) + (b t)
 (-) a b = \t -> (a t) - (b t)
 (*) a b = \t -> (a t) * (b t)
 sqrt a = \t -> sqrt (a t)

I followed the compiler advice to produce the following version which

{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeSynonymInstances #-}
module MovingPoint where
type Time  = Float -- Type synonym assumed, could it be data type??
type Moving v  = Time -> v

class Number a where
 (+), (-), (*) ::  a -> a  -> a
 sqr  ::   a -> a
 sqrt ::  a -> a

instance (Floating v) => Number (Moving v) where
 (+) a b = \t -> (a t)  Prelude.+ (b t)
 (-) a b = \t -> (a t)  Prelude.- (b t)
 (*) a b = \t -> (a t)  Prelude.* (b t)
 sqr a =  \t -> (a t)  Prelude.* (a t)
 sqrt a =  \t -> Prelude.sqrt (a t)

I do not know how to invoke any of the operations. In general I do know how
to execute lambdas.
I do not understand the bracketed pairs e.g. (a t).
Any help on understanding and running the program would be appreciated.

[1] Ontology for Spatio-temporal Databases


This email originated from DIT. If you received this email in error, please 
delete it from your system. Please note that if you are not the named 
addressee, disclosing, copying, distributing or taking any action based on 
the contents of this email or attachments is prohibited. www.dit.ie

Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí 
earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an 
seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon 
dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa 
ríomhphost nó sna hiatáin seo. www.dit.ie

Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to 
Grangegorman <http://www.dit.ie/grangegorman>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20171003/546eb846/attachment.html>

More information about the Beginners mailing list