[Haskell-beginners] Return type from class method

PATRICK BROWNE patrick.browne at dit.ie
Sat Oct 7 12:07:43 UTC 2017

Is there a way rewriting the definition of (+) so that testPlusArg returns
a (Moving Double). My current intuition is that the signature [(+)  ::  a
-> a  -> a] says that the type should be the same as the arguments. And
indeed (:t testPlus) confirms this. But the type of  testPlusArg is a
 Can I make it (Moving Double) ?

{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeSynonymInstances #-}
module Moving where
data  Time  = Time Double
type Moving v  = Time -> v

class  Number a where
 (+)  ::  a -> a  -> a

instance Number  (Moving Double) where
 (+) a b = \t -> ((a t) Prelude.+ (b t))

a,b ::  Moving Double
a (Time x) = 2.0
b (Time x) = 2.0
testPlus ::(Moving Double)
testPlus = (a Moving.+ b)
testPlusArg = (a Moving.+ b) (Time 2.0)


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/20171007/e03d5933/attachment.html>

More information about the Beginners mailing list