開発中の言語の型推論アルゴリズムを探していますが、通常は次のいずれかであるため、自分のニーズに合った型推論アルゴリズムを見つけることができませんでした。
- アラモスHaskell、多態性はあるがアドホックなオーバーロードはない
- アラカルトC ++(自動)で、アドホックなオーバーロードはあるが、関数は単相
特に、私のタイプシステムは(簡素化)です(Haskellish構文を使用していますが、これは言語に依存しません)。
data Type = Int | Double | Matrix Type | Function Type Type
そして、私はかなりのオーバーロードを持っている演算子*を持っています:
Int -> Int -> Int
(Function Int Int) -> Int -> Int
Int -> (Function Int Int) -> (Function Int Int)
(Function Int Int) -> (Function Int Int) -> (Function Int Int)
Int -> Matrix Int -> Matrix Int
Matrix Int -> Matrix Int -> Matrix Int
(Function (Matrix Int) (Matrix Int)) -> Matrix Int -> Matrix Int
等...
そして、私は可能なタイプを推測したい
(2*(x => 2*x))*6
(2*(x => 2*x))*{{1,2},{3,4}}
1つ目はInt
、2つ目Matrix Int
です。
例(機能しない):
{-# LANGUAGE OverlappingInstances, MultiParamTypeClasses,
FunctionalDependencies, FlexibleContexts,
FlexibleInstances, UndecidableInstances #-}
import qualified Prelude
import Prelude hiding ((+), (*))
import qualified Prelude
newtype WInt = WInt { unwrap :: Int }
liftW f a b = WInt $ f (unwrap a) (unwrap b)
class Times a b c | a b -> c where
(*) :: a -> b -> c
instance Times WInt WInt WInt where
(*) = liftW (Prelude.*)
instance (Times a b c) => Times a (r -> b) (r -> c) where
x * g = \v -> x * g v
instance Times (a -> b) a b where
f * y = f y
two = WInt 2
six = WInt 6
test :: WInt
test = (two*(\x -> two*x))*six
main = undefined