Is it a bad idea to define some, but not all methods of a type class in Haskell? -
want this:
data point = point double double instance num point (point ax ay) + (point bx by) = point (ax + bx) (ay + by) negate (point ax ay) = point (negate ax) (negate ay) syntastic doesn't it. wants me define methods *, abs, frominteger , signum.
what's recommended way me + , - operator defined point without taking on rest?
also, define different kinds of scalar , vector multiplication double * point or point * point in cross-product or dot-product sense. type scheme isn't friend here, right?
and + operator can think of? why not +/? or +.? what's wrong them?
yes, leaving members of class unimplemented bad form.
as lastly resort, define own typeclass this
import prelude hiding ((+)) import qualified prelude ((+)) class plus c (+) :: c -> c -> c instance plus double (+) = prelude.(+) instance plus point point x1 y1 + point x2 y2 = point (x1 + x2) (y1 + y2) haskell
No comments:
Post a Comment