개발중인 언어에 대한 형식 유추 알고리즘을 찾고 있지만 일반적으로 다음 중 하나이므로 내 요구에 맞는 것을 찾을 수 없습니다.
- La Haskell, 다형성, 임시 과부하 없음
- a-임시 오버로드가 있지만 기능이 단일 한 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}}
첫 번째는 Int
두 번째 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