728x90
Type of the head function
head takes a list of any type and returns the first element. The type declaration of head states that it takes a list of any type and returns one element of that type.
- ghci> :t head
- head :: [a] -> a
What is this a? Types are written in capital case, so it can't exactly be a type. It's actually a type variable. That means that a can be of any type.
polymorphic functions : Functions that have type variables.
Type of the fst function
- ghci> :t fst
- fst :: (a, b) -> a
fst takes a tuple which contains two types and returns an element which is of the same type as the pair's first component.
Because a and b are different type variables, they don't have to be different types. It just states that the first component's type and the return value's type are the same.
본 카테고리의 내용은 Learn You a Haskell for Great Good! 의 내용을 학습을 위해 요약한 것입니다.
728x90
'프로그래밍 Programming' 카테고리의 다른 글
Haskell Type, Typeclass, and Type variables (0) | 2018.03.16 |
---|---|
Haskell_ 003 Typeclass (0) | 2018.03.15 |
Haskell_ 001 Type and typeclass (0) | 2018.03.05 |
하스켈 패키지 삭제하기 How to uninstall a Haskell package installed with stack? (0) | 2018.02.06 |
cabal install 사용방법 (1) How to cabal install (1) (0) | 2018.02.06 |