문제

Suppose that the function gets as its input two variables of different types (e.g. one variable is int in the language of C, and one variable is char in the language of C) and returns one variable that is in Int.

If this function is coded as Haskell or lambda calculus code, how would the function's type be?

So suppose that the function has type Int -> (Char -> Char) -> Int. What would this mean? Would this mean that it receives int variable as input and runs function of (Char -> Char) and outputs Int variable?

도움이 되었습니까?

해결책

A type of Int -> (Char -> Char) -> Int would mean the function accepts an Int and a function of type Char -> Char as input, and outputs an Int.

The function doesn't have to actually use its inputs per se. For example,

meetoosFunction :: Int -> (Char -> Char) -> Int
meetoosFunction _ _ = 42

*Main Data.Char> meetoosFunction 1 toUpper
42
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top