Created
July 15, 2017 09:32
-
-
Save mizukmb/dc19cb0a46e200681ff8d1f37675f619 to your computer and use it in GitHub Desktop.
This file contains 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
data Vector a = Vector a a a deriving (Show) | |
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) | |
dotProd :: (Num a) => Vector a -> Vector a -> a | |
(Vector i j k) `dotProd` (Vector l m n) = i*l + j*m + k*n | |
vmult :: (Num a) => Vector a -> a -> Vector a | |
(Vector i j k) `vmult` m = Vector (i*m) (j*m) (j*m) |
値コンストラクタは引数を渡すと定義された型を返す関数?
関数なので VVector -> Int
のように型宣言には使えない( True -> Int
とは書けないのと同じ。 True
は型じゃない)。
ちなみにデータ型と値コンストラクタの命名は同じにするのが慣例っぽい。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
という感じに値コンストラクタを
VVector
にしてみた。(型コンストラクタと値コンストラクタの違いをわかりやすくするため)