[ngrams] improve function documentation, add types, add unit tests

I want to understand ngrams algorithms better.
4 jobs for 224-dev-understanding-ngrams in 55 minutes and 26 seconds (queued for 5 seconds)
Status Job ID Name Coverage
  Cabal
passed #16632
cabal

00:21:54

 
  Stack
passed #16633
stack

00:07:30

 
  Bench
manual #16634
allowed to fail manual
bench
 
  Test
passed #16635
test

00:26:01