What if the application was a class?

Suppose the Haskell function application (the "space" operator) was in the class, instead of baking the language. I guess it will look like

class Apply f where ($) :: far -> a -> r instance Apply (->) where ($) = builtinFnApply# 

And fa will desugar to f $ a . The idea is that this will allow you to define other types that act as functions, i.e.

 instance Apply LinearMap where ($) = matrixVectorMult 

etc.

Does this make type inference unsolvable? My instinct says that it is, but my understanding of type inference dwells on a simple Hindley-Milner. As a continuation, if it is not decidable, can it be decidable by prohibiting certain pathological cases?

+5
source share
1 answer

If you can imagine it as syntactic sugar on top of Haskell (replacing the “space operator” with yours), I don’t understand why this should make the type inference worse than it is.

However, I can see that this code may be more ambiguous with this change, for example.

 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)) 

The above get can be selected from both instances, while such ambiguity does not occur in plain Haskell.

+5
source

Source: https://habr.com/ru/post/1242601/


All Articles