You can define the function signature in the ghc interactive shell. However, the problem is that you need to define functions in one command .
You can use a semicolon ( ; ) to separate between two parts:
Prelude> square :: Int -> Int; square x = x * x
Note that the same is true for a function with multiple sentences . If you write:
Prelude> is_empty [] = True Prelude> is_empty (_:_) = False
Actually, the previous is_empty function is is_empty with the second statement. If we then request an empty list, we get:
Prelude> is_empty [] *** Exception: <interactive>:4:1-22: Non-exhaustive patterns in function is_empty
So ghci has adopted the latter definition as the definition of the function of a single sentence.
Again you need to write it like:
Prelude> is_empty[] = True ; is_empty (_:_) = False
source share