Skip to content

Instantly share code, notes, and snippets.

@motokiee
Created November 6, 2015 04:54
Show Gist options
  • Save motokiee/37419682b94429e2b2e3 to your computer and use it in GitHub Desktop.
Save motokiee/37419682b94429e2b2e3 to your computer and use it in GitHub Desktop.
久しぶりのランチタイム勉強 #CodePiece
-- data Person = Person String String Int Float String String deriving (Show)
data Person = Person { firstName :: String,
lastName :: String,
age :: Int,
height :: Float,
phoneNumber :: String,
flavor :: String
} deriving (Show)
data Car = Car { company :: String,
model :: String,
year :: Int
} deriving (Show)
data IntMayby a = INothing | IJust Int
-- データ宣言には型クラス制約をつけない
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) (k*m)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment