Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell 如果函数应用程序是一个类型类呢?_Haskell_Type Inference - Fatal编程技术网

Haskell 如果函数应用程序是一个类型类呢?

Haskell 如果函数应用程序是一个类型类呢?,haskell,type-inference,Haskell,Type Inference,假设Haskell的函数应用程序(“space”操作符)位于typeclass中,而不是烘焙到语言中。我想它看起来像 class Apply f where ($) :: f a r -> a -> r instance Apply (->) where ($) = builtinFnApply# 而fa会将糖份减至fa。其思想是,这将允许您定义与函数类似的其他类型,即 instance Apply LinearMap where ($) = matr

假设Haskell的函数应用程序(“space”操作符)位于typeclass中,而不是烘焙到语言中。我想它看起来像

class Apply f where
    ($) :: f a r -> a -> r

instance Apply (->) where
   ($) = builtinFnApply#
fa
会将糖份减至
fa
。其思想是,这将允许您定义与函数类似的其他类型,即

instance Apply LinearMap where
    ($) = matrixVectorMult
等等


这会使类型推理无法判定吗?我的直觉说是的,但我对类型推理的理解停留在普通的欣德利·米尔纳身上。作为后续,如果它是不可判定的,是否可以通过取缔某些病理实例来判定它?

如果你可以将其想象为Haskell之上的一个语法糖(用你的替换“空格运算符”),我不明白为什么这会使类型推断变得比现在更糟糕

但是,我可以看到,代码可能会因为这个更改而变得更加模糊,例如

class C a where get :: a
instance C (Int -> Int) where get = id
instance C Linearmap where get = ...

test = get (5 :: Int) -- actually being (get $ (5 :: Int))
上面的
get
可以从这两个实例中选取,而在普通Haskell中不会出现这种歧义