Skip to content

Validate Swedish personal identity numbers

License

Notifications You must be signed in to change notification settings

personnummer/haskell

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

haskell-personnummer

Test and lint

Validate Swedish personal identity numbers with Haskell

Usage

import Personnummer (isValid, toPersonnummer)

pnrIsValid :: Bool
pnrIsValid = isValid $ fromJust toPersonnummer "19900101-0017"

Run example

PATH=$(brew --prefix)/opt/llvm/bin:$PATH cabal run Personnummer  \
  --ghc-option=-fllvm

REPL

$ 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

Test

cabal test --ghc-option=-fllvm

Formatter

ormolu

If you're using VS Code, configure

{
  "haskell.formattingProvider": "ormolu"
}