Haskell: type deduction function

So, today I played with Haskell, thinking about auto-generating function definitions defined by a type.

For example, a function definition

twoply :: (a -> b, a -> c) -> a -> (b, c)

obvious to me, given the type (if I exclude the use undefined :: a).

So, I came up with the following:

ยข :: a -> (a ->b) -> b
ยข = flip ($)

What has an interesting property, that

(ยข) ยข ($) :: a -> (a -> b) -> b

This brings me to my question. If the relation =::=for "has the same type as", then does the operator x =::= x x ($)uniquely determine the type x? Should x =::= ยข, or is there another possible type for x?

I tried to back away x =::= x x ($)to get out x :: a -> (a -> b) -> b, but got bogged down.

+3
source share
3 answers

x =::= x x ($) x = const, a -> b -> a. , .

+8
+8

From the above equation, we can determine some type signature for x. X does not have to have this type, but it should at least be combined with this type.

$ :: forall a b. (a -> b) -> a -> b
x :: t1 -> ((a -> b) -> a -> b) -> t1

Given this, it should be easy to write many implementations of x.

+1
source

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


All Articles