How to get the first char from a string in Haskell
Overview
In this shot, we'll learn how to use Haskell to get the first character from a string. We can use the take function provided by Haskell to get the first character from a string.
Syntax
take n "provide string here"
Here, n denotes the number of characters to get. We provide n = 1 to get the first character from the given string.
Let's see an example:
Example
main::IO()main = do-- get first character from a stringprint(take 1 "hello world")
Explanation
- Line 5: We print the first character of the string using the function
takeand passnas1.