Monday 6 June 2016

Haskell: Check whether two strings are equal or not


StringsEqual.hs
stringsEqual :: String -> String -> Bool
stringsEqual [] [] = True
stringsEqual _ [] = False
stringsEqual [] _ = False
stringsEqual (x:xs) (y:ys) = (x == y) && stringsEqual xs ys

*Main> :load StringsEqual.hs
[1 of 1] Compiling Main             ( StringsEqual.hs, interpreted )
Ok, modules loaded: Main.
*Main> 
*Main> stringsEqual [] [] 
True
*Main> stringsEqual "Hello" "Hello"
True
*Main> stringsEqual "Hello" "Hello1"
False
*Main> stringsEqual "Hello1" "Hello"
False
*Main> 


Previous                                                 Next                                                 Home

No comments:

Post a Comment