Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if string starts with other string in Haskell

Tags:

haskell

I'd like to know whether my string starts with another string. For example:

startsWith "(" "(test string)" == True

Is there such a function that comes with Haskell?

like image 747
Matthias Braun Avatar asked May 17 '19 13:05

Matthias Braun


1 Answers

Since strings are lists of characters, we can import Data.List and use the general function isPrefixOf:

isPrefixOf :: Eq a => [a] -> [a] -> Bool

Example:

Prelude Data.List> isPrefixOf "abc" "abcxyz"
True
like image 129
3 revs, 3 users 57% Avatar answered Sep 29 '22 01:09

3 revs, 3 users 57%