Skip to content

Instantly share code, notes, and snippets.

@zenloner
Created June 6, 2013 01:06
Show Gist options
  • Save zenloner/5718600 to your computer and use it in GitHub Desktop.
Save zenloner/5718600 to your computer and use it in GitHub Desktop.
-- there is only a after the first of Vector
-- a like T in C++ template, declare once and use many times
data Vector a = Vector a a a deriving (Show)
--use => as the delimiter of type constraint and type declaration
-- there is also only one a after Vector, because Vector a is a type and Vector a a a is a type constructor, there are only types in a type declaration, not any type constructors
vplus::(Num a) => Vector a->Vector a->Vector a
(Vector i j k) `vplus` (Vector l m n) = Vector (i+l) (j+m) (k+n)
main = do
print $ Vector 1 2 3 `vplus` Vector 4 5 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment