IBAN: Difference between revisions

77 bytes removed ,  7 years ago
(Added FreeBASIC)
Line 1,517:
This program uses the Maybe and Either monads to handle failures. Values of type 'Maybe a' can contain 'Nothing' (no value) or 'Just a' (a value of type 'a'). Values of type 'Either a b' contain 'Left b' (usually indicating failure) or 'Right c' (usually indicating success).
<lang Haskell>import Data.Char (toUpper)
import Data.Maybe (fromJust)
 
validateIBAN :: String -> Either String String
Line 1,556 ⟶ 1,557:
-- convert the result to an integer
p4 :: Integer
p4 = read $ concat $ convertLettersmap convertLetter p3
convertLettersconvertLetter []x | x `elem` digits = [x]
| otherwise = let (Just ys) = fromJust $ lookup x replDigits
convertLetters (x:xs)
| x `elem` digits = [x] : convertLetters xs
| otherwise = let (Just ys) = lookup x replDigits
in ys : convertLetters xs
-- see if the number is valid
check = if sane
Anonymous user