Function Type Definition in Functional Programming

The following equations are written in Miranda's syntax, but due to the similarities between Miranda and Haskell, I expect Haskell programmers to understand this!

If you define the following functions:

rc v g i = g (v:i)
rn x = x
rh g = hd (g [])


f [] y = y 
f (x:xs) y = f xs (rc x y)

g [] y = y
g (x:xs) y = g xs (x:y)

How do you determine the type of functions? I think I understand how to do this for f, g and rn, but I am confused by the partial part of the application.

rn will be * → * (or anything → something, I think a → a in Haskell?)

For f and g - types of functions as [*] → * → * ?

, rc rh. rc g - , [*]. rc g rc? g i, , rc? rc 3 v, g i? . ! , .

, , hd head :

hd :: [*] -> *
hd (a:x) = a
hd [] = error "hd []"
+5
2

, .

,

rc v g i = g (v : i)

so rc :: a -> b -> c -> d, , a, b, c d. (v : i), v :: a , i :: [a], c = [a]. g v : i, g :: [a] -> d, ,

rc :: a -> ([a] -> d) -> [a] -> d

rn x = x , rn , rn :: a -> a.

rh g = hd (g [])

rh g RHS, [a] -> b, , a b. , g [] hd RHS, g [] :: [c] g :: [a] -> [c], ,

rh :: ([a] -> [c]) -> c

f [] y = y 
f (x:xs) y = f xs (rc x y)

- , , , f :: [a] -> b -> b . RHS f rc x y, rc x y , y, b.

rc :: a -> ([a] -> d) -> [a] -> d

b = [a] -> d.

f :: [a] -> ([a] -> d) -> [a] -> d

g [] y = y
g (x:xs) y = g xs (x:y)

g :: [a] -> b -> b. b = [a], g , ,

g :: [a] -> [a] -> [a]
+6

haskell .

rc v g i = g (v:i)

rc , - a -> b -> c -> d. v:i , v i, v :: a i :: [a]. g , g :: [a] -> d. , rc :: a -> ([a] -> d) -> [a] -> d.

rn :: a -> a, .

hd, rh, .

f [] y = y 
f (x:xs) y = f xs (rc x y)

f , - a -> b -> c. , b == c, y . , f :: [a'] -> b -> b. , x y rc: y [a'] -> d rc x y :: a' -> d ( y, f). , , f :: [a'] -> ([a'] -> d) -> ([a'] -> d). -> -, [a'] -> ([a'] -> d) -> [a'] -> d.

.

+6

All Articles