Validate Swedish personal identity numbers with Haskell
import Personnummer (isValid, toPersonnummer)
pnrIsValid :: Bool
pnrIsValid = isValid $ fromJust toPersonnummer "19900101-0017"
PATH=$(brew --prefix)/opt/llvm/bin:$PATH cabal run Personnummer \
--ghc-option=-fllvm
$ cabal repl
*Personnummer> isValidString "199001010018"
Fasle
$ cabal repl
*Personnummer> let pnr = fromJust $ toPersonnummer "9001010017"
*Personnummer> isValid pnr
True
*Personnummer> gender pnr
Male
*Personnummer> isFemale pnr
False
*Personnummer> format pnr True
"19900101-0017"
*Personnummer> getAge pnr
32
cabal test --ghc-option=-fllvm
If you're using VS Code, configure
{
"haskell.formattingProvider": "ormolu"
}