ฉันกำลังมองหาอัลกอริทึมการอนุมานแบบสำหรับภาษาที่ฉันกำลังพัฒนา แต่ฉันไม่พบสิ่งที่ตรงกับความต้องการของฉันเพราะพวกเขามักจะเป็น:
- à la Haskell ด้วยความหลากหลาย แต่ไม่มีโฆษณามากเกินไป
- à la C ++ (อัตโนมัติ) ที่คุณมีการโหลดมากเกินไปแบบ ad-hoc แต่ฟังก์ชั่นเป็น monomorphic
โดยเฉพาะอย่างยิ่งระบบพิมพ์ของฉันคือ (ลดความซับซ้อน) (ฉันใช้ไวยากรณ์ 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