Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

a program that returns true if a string contains only digits

Tags:

haskell

I want to make a program that returns true if a string contains only digits in Haskell.

This is my attempt:

checkNum :: String -> Bool
checkNum xs = ((length (filter isDigit xs )) == length (xs))

This is the error I get:

Not in scope: `isDigit'

What's wrong with my code?

like image 849
Ohad Avatar asked Oct 15 '25 16:10

Ohad


1 Answers

This should work:

import Data.Char (isDigit)

checkNum :: String -> Bool
checkNum = all isDigit
like image 91
Chris Taylor Avatar answered Oct 18 '25 07:10

Chris Taylor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!