Created
June 3, 2018 03:43
-
-
Save KeenS/883eb276d45ac8553a60b664d5209313 to your computer and use it in GitHub Desktop.
GHCで {リスト,スカラ} x {リスト,スカラ}演算のオーバーロード
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
{-#LANGUAGE TypeFamilies, MultiParamTypeClasses, FlexibleInstances #-} | |
class Overload a b where | |
type Out a b :: * | |
(+):: a -> b -> Out a b | |
instance Overload Int Int where | |
type Out Int Int = Int | |
(+) = (Prelude.+) | |
instance Overload [Int] Int where | |
type Out [Int] Int = [Int] | |
(+) a b = map (Prelude.+ b) a | |
instance Overload Int [Int] where | |
type Out Int [Int] = [Int] | |
(+) a b = map (a Prelude.+) b | |
instance Overload [Int] [Int] where | |
type Out [Int] [Int] = [Int] | |
(+) a b = map (uncurry (Prelude.+)) $ zip a b | |
main :: IO () | |
main = return () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment