मैं एक ऐसी भाषा के लिए एक प्रकार का अनुमान एल्गोरिथ्म खोज रहा हूं, जिसे मैं विकसित कर रहा हूं, लेकिन मुझे वह नहीं मिला, जो मेरी आवश्यकताओं के अनुरूप हो, क्योंकि वे आमतौर पर हैं:
- एक ला हास्केल, बहुरूपता के साथ, लेकिन कोई तदर्थ ओवरलोडिंग नहीं
- A la C ++ (ऑटो) जिसमें आपके पास तदर्थ ओवरलोडिंग है लेकिन फ़ंक्शन मोनोमोर्फिक हैं
विशेष रूप से मेरी टाइप प्रणाली है (सरलीकृत) (मैं हास्केलिश सिंटैक्स का उपयोग कर रहा हूं लेकिन यह भाषा अज्ञेय है):
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