Created
June 6, 2013 01:06
-
-
Save zenloner/5718600 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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