Foreign.C.Types
Foreign.C.Types
C 함수 프로토타입을 정확하게 나타내는 데 필요한 C 타입들의 표현을 제공하는 모듈이에요.
본문
module Foreign.C.Types (
CChar, CSChar, CUChar, CShort, CUShort, CInt, CUInt, CLong, CULong,
CPtrdiff, CSize, CWchar, CSigAtomic, CLLong, CULLong, CIntPtr,
CUIntPtr, CIntMax, CUIntMax, CClock, CTime, CFloat, CDouble, CFile,
CFpos, CJmpBuf
) where
28.1 C 타입의 표현 (Representations of C types)
이 타입들은 Haskell에서 C 라이브러리 인터페이스에 접근하기 위해 C 함수 프로토타입을 정확하게 나타내는 데 필요해요. Haskell 시스템이 C 타입을 C와 똑같은 방식으로 표현할 필요는 없지만, C 타입 t를 나타내는 Haskell 타입 CT에 관해 다음의 보장이 제공돼요.
- C 함수 프로토타입이
t를 인자 타입이나 결과 타입으로 가진다면, 외부(foreign) 선언의 해당 위치에서CT를 사용하면 Haskell 프로그램이 C 타입으로 인코딩된 값의 전체 범위에 접근할 수 있어요. 그리고 그 역으로,CT의 어떤 Haskell 값에도 C에서 유효한 표현이 존재해요. sizeOf (undefined :: CT)는 C에서sizeof (t)와 같은 값을 산출해요.alignment (undefined :: CT)는 C 구현이t에 대해 강제하는 정렬(alignment) 제약과 일치해요.Storable클래스의peek와poke멤버는CT의 모든 값을t의 대응 값으로, 그 반대 방향으로도 매핑해요.CT에 대해Bounded인스턴스가 정의되면,minBound와maxBound의 값은 C에서t_MIN과t_MAX와 일치해요.CT에 대해Eq또는Ord인스턴스가 정의되면, 타입 클래스에 의해 정의된 술어는 C에서t에 대한 대응 술어와 같은 관계를 구현해요.CT에 대해Num,Read,Integral,Fractional,Floating,RealFrac, 또는RealFloat인스턴스가 정의되면, 타입 클래스에 의해 정의된 산술 연산은 (가능하다면) C에서t에 대한 대응 산술 연산과 같은 함수를 구현해요.CT에 대해Bits인스턴스가 정의되면, 타입 클래스에 의해 정의된 비트 연산은 C에서t에 대한 대응 비트 연산과 같은 함수를 구현해요.
28.1.1 정수 타입 (Integral types)
이 타입들은 Data.Int와 Data.Word의 타입들의 newtype으로 표현되며, Eq, Ord, Num, Read, Show, Enum, Storable, Bounded, Real, Integral, Bits의 인스턴스예요.
data CChar
C의 char 타입을 나타내는 Haskell 타입이에요.
instance Bounded CChar instance Enum CChar
instance Eq CChar
instance Integral CChar
instance Num CChar instance Ord CChar
instance Read CChar
instance Real CChar
instance Show CChar
instance Storable CChar
instance Bits CChar
data CSChar
C의 signed char 타입을 나타내는 Haskell 타입이에요.
instance Bounded CSChar instance Enum CSChar
instance Eq CSChar
instance Integral CSChar
instance Num CSChar instance Ord CSChar
instance Read CSChar
instance Real CSChar
instance Show CSChar
instance Storable CSChar
instance Bits CSChar
data CUChar
C의 unsigned char 타입을 나타내는 Haskell 타입이에요.
instance Bounded CUChar instance Enum CUChar
instance Eq CUChar
instance Integral CUChar
instance Num CUChar instance Ord CUChar
instance Read CUChar
instance Real CUChar
instance Show CUChar
instance Storable CUChar
instance Bits CUChar
data CShort
C의 short 타입을 나타내는 Haskell 타입이에요.
instance Bounded CShort instance Enum CShort
instance Eq CShort
instance Integral CShort
instance Num CShort instance Ord CShort
instance Read CShort
instance Real CShort
instance Show CShort
instance Storable CShort
instance Bits CShort
data CUShort
C의 unsigned short 타입을 나타내는 Haskell 타입이에요.
instance Bounded CUShort instance Enum CUShort
instance Eq CUShort
instance Integral CUShort
instance Num CUShort instance Ord CUShort
instance Read CUShort
instance Real CUShort
instance Show CUShort
instance Storable CUShort
instance Bits CUShort
data CInt
C의 int 타입을 나타내는 Haskell 타입이에요.
instance Bounded CInt instance Enum CInt
instance Eq CInt
instance Integral CInt
instance Num CInt instance Ord CInt
instance Read CInt
instance Real CInt
instance Show CInt
instance Storable CInt
instance Bits CInt
data CUInt
C의 unsigned int 타입을 나타내는 Haskell 타입이에요.
instance Bounded CUInt instance Enum CUInt
instance Eq CUInt
instance Integral CUInt
instance Num CUInt instance Ord CUInt
instance Read CUInt
instance Real CUInt
instance Show CUInt
instance Storable CUInt
instance Bits CUInt
data CLong
C의 long 타입을 나타내는 Haskell 타입이에요.
instance Bounded CLong
instance Enum CLong
instance Eq CLong
instance Integral CLong
instance Num CLong
instance Ord CLong
instance Read CLong
instance Real CLong
instance Show CLong
instance Storable CLong
instance Bits CLong
data CULong
C의 unsigned long 타입을 나타내는 Haskell 타입이에요.
instance Bounded CULong
instance Enum CULong
instance Eq CULong
instance Integral CULong
instance Num CULong
instance Ord CULong
instance Read CULong
instance Real CULong
instance Show CULong
instance Storable CULong
instance Bits CULong
data CPtrdiff
C의 ptrdiff_t 타입을 나타내는 Haskell 타입이에요.
instance Bounded CPtrdiff instance Enum CPtrdiff
instance Eq CPtrdiff
instance Integral CPtrdiff
instance Num CPtrdiff instance Ord CPtrdiff
instance Read CPtrdiff
instance Real CPtrdiff
instance Show CPtrdiff
instance Storable CPtrdiff
instance Bits CPtrdiff
data CSize
C의 size_t 타입을 나타내는 Haskell 타입이에요.
instance Bounded CSize instance Enum CSize
instance Eq CSize
instance Integral CSize
instance Num CSize instance Ord CSize
instance Read CSize
instance Real CSize
instance Show CSize
instance Storable CSize
instance Bits CSize
data CWchar
C의 wchar_t 타입을 나타내는 Haskell 타입이에요.
instance Bounded CWchar instance Enum CWchar
instance Eq CWchar
instance Integral CWchar
instance Num CWchar instance Ord CWchar
instance Read CWchar
instance Real CWchar
instance Show CWchar
instance Storable CWchar
instance Bits CWchar
data CSigAtomic
C의 sig_atomic_t 타입을 나타내는 Haskell 타입이에요.
instance Bounded CSigAtomic
instance Enum CSigAtomic
instance Eq CSigAtomic
instance Integral CSigAtomic
instance Num CSigAtomic
instance Ord CSigAtomic
instance Read CSigAtomic
instance Real CSigAtomic
instance Show CSigAtomic
instance Storable CSigAtomic
instance Bits CSigAtomic
data CLLong
C의 long long 타입을 나타내는 Haskell 타입이에요.
instance Bounded CLLong
instance Enum CLLong
instance Eq CLLong
instance Integral CLLong
instance Num CLLong
instance Ord CLLong
instance Read CLLong
instance Real CLLong
instance Show CLLong
instance Storable CLLong
instance Bits CLLong
data CULLong
C의 unsigned long long 타입을 나타내는 Haskell 타입이에요.
instance Bounded CULLong
instance Enum CULLong
instance Eq CULLong
instance Integral CULLong
instance Num CULLong
instance Ord CULLong
instance Read CULLong
instance Real CULLong
instance Show CULLong
instance Storable CULLong
instance Bits CULLong
data CIntPtr
C의 intptr_t 타입을 나타내는 Haskell 타입이에요.
instance Bounded CIntPtr instance Enum CIntPtr
instance Eq CIntPtr
instance Integral CIntPtr
instance Num CIntPtr instance Ord CIntPtr
instance Read CIntPtr
instance Real CIntPtr
instance Show CIntPtr
instance Storable CIntPtr
instance Bits CIntPtr
data CUIntPtr
C의 uintptr_t 타입을 나타내는 Haskell 타입이에요.
instance Bounded CUIntPtr instance Enum CUIntPtr
instance Eq CUIntPtr
instance Integral CUIntPtr
instance Num CUIntPtr instance Ord CUIntPtr
instance Read CUIntPtr
instance Real CUIntPtr
instance Show CUIntPtr
instance Storable CUIntPtr
instance Bits CUIntPtr
data CIntMax
C의 intmax_t 타입을 나타내는 Haskell 타입이에요.
instance Bounded CIntMax instance Enum CIntMax
instance Eq CIntMax
instance Integral CIntMax
instance Num CIntMax instance Ord CIntMax
instance Read CIntMax
instance Real CIntMax
instance Show CIntMax
instance Storable CIntMax
instance Bits CIntMax
data CUIntMax
C의 uintmax_t 타입을 나타내는 Haskell 타입이에요.
instance Bounded CUIntMax instance Enum CUIntMax
instance Eq CUIntMax
instance Integral CUIntMax
instance Num CUIntMax instance Ord CUIntMax
instance Read CUIntMax
instance Real CUIntMax
instance Show CUIntMax
instance Storable CUIntMax
instance Bits CUIntMax
28.1.2 수치 타입 (Numeric types)
이 타입들은 기본 외부 타입(basic foreign types)들의 newtype으로 표현되며, Eq, Ord, Num, Read, Show, Enum, Storable의 인스턴스예요.
data CClock
C의 clock_t 타입을 나타내는 Haskell 타입이에요.
instance Enum CClock instance Eq CClock
instance Num CClock instance Ord CClock
instance Read CClock
instance Real CClock
instance Show CClock
instance Storable CClock
data CTime
C의 time_t 타입을 나타내는 Haskell 타입이에요.
instance Enum CTime instance Eq CTime
instance Num CTime instance Ord CTime
instance Read CTime
instance Real CTime
instance Show CTime
instance Storable CTime
28.1.3 부동소수점 타입 (Floating types)
이 타입들은 Float와 Double의 newtype으로 표현되며, Eq, Ord, Num, Read, Show, Enum, Storable, Real, Fractional, Floating, RealFrac, RealFloat의 인스턴스예요.
data CFloat
C의 float 타입을 나타내는 Haskell 타입이에요.
instance Enum CFloat instance Eq CFloat
instance Floating CFloat
instance Fractional CFloat instance Num CFloat
instance Ord CFloat
instance Read CFloat
instance Real CFloat
instance RealFloat CFloat
instance RealFrac CFloat
instance Show CFloat
instance Storable CFloat
data CDouble
C의 double 타입을 나타내는 Haskell 타입이에요.
instance Enum CDouble instance Eq CDouble
instance Floating CDouble
instance Fractional CDouble instance Num CDouble
instance Ord CDouble
instance Read CDouble
instance Real CDouble
instance RealFloat CDouble
instance RealFrac CDouble
instance Show CDouble
instance Storable CDouble
28.1.4 기타 타입 (Other types)
data CFile
C의 FILE 타입을 나타내는 Haskell 타입이에요.
data CFpos
C의 fpos_t 타입을 나타내는 Haskell 타입이에요.
data CJmpBuf
C의 jmp_buf 타입을 나타내는 Haskell 타입이에요.
더 알아보기 (Learn more)
- 28.1절의 서술처럼 C 타입 표현이 만족해야 하는 보장을 다시 확인해 보세요.
- C 문자열·와이드 문자열 변환은 27장 Foreign.C.String에서 다뤄요.