갈루아의 반서재

하스켈에서 juxtaposition 는 함수호출을 나타낸다. 아래와 같은 함수들은 이미 ghci 가 시작될 때 로딩되는 Haskell "Prelude" 에 정의되어 있다. 아래 링크에서 추가적인  함수들을 살펴볼 수 있다.

http://zvon.org/other/haskell/Outputprelude/index.html


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Prelude> negate 3
-3
it :: Num a => a
 
Prelude> even 5
False
it :: Bool
 
Prelude> pred 'C'
'B'
it :: Char
 
Prelude> signum 2
1
it :: Num a => a
cs

negate change the sign of the number.

even returns True if the integral is even, False otherwise.

pred returns preceding item in an enumeration.

signum returns -1 for negative numbers, 0 for zero, and 1 for positive numbers.


그리고 ghci 는 GNU Readline library 를 사용한다. 아래를 참조한다.

GNU Readline Library

http://tiswww.case.edu/php/chet/readline/rluserman.html


병치함수호출(Function call with juxtaposition)은 왼쪽 결합이다. 

즉 아래의 예에서 signum negate 2 의 경우는 (signum negate) 2 을 의미하는 것이다.

1
2
3
4
5
6
7
Prelude> signum negate 2
 
<interactive>:16:1:
    Non type-variable argument in the constraint: Num (a -> a)
    (Use FlexibleContexts to permit this)
    When checking that ‘it’ has the inferred type
      it :: forall a. (Num a, Num (a -> a)) => a
cs

따라서 negate 2 를 먼저 호출하려면 괄호로 묶어야 한다.

1
2
3
Prelude> signum (negate 2)
-1
it :: Num a => a
cs


그리고 병치함수호출은 다른 어떤 연산자보다 높은 우선순위를 갖는다.

1
2
3
4
Prelude> negate 3+4
1
it :: Num a => a
 
cs

즉 여기서 negate 3 + 4 는 (negate 3) + 4 를 의미한다. + 를 먼저 적용할려면 아래와 같이 괄호를 쳐야한다.

1
2
3
4
5
6
7
Prelude> negate (3+4)
-7
it :: Num a => a
 
Prelude> signum (negate (3+4))
-1
it :: Num a => a
cs