Hlint fixes

This commit is contained in:
Mats Rauhala 2019-10-15 23:13:34 +03:00
parent e347b4753b
commit 7c8a298f71
2 changed files with 5 additions and 6 deletions

View File

@ -1,6 +1,5 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
@ -63,6 +62,6 @@ handler =
findBest :: Model -> Text -> Either Text Text
findBest model sentence =
let caesared = map (\n -> T.map (caesar n) . T.toLower $ sentence) [0..29]
ranked = sortOn fst $ [(goodness model x, x) | x <- caesared]
ranked = sortOn fst [(goodness model x, x) | x <- caesared]
found = find (\(rank, _) -> rank > -7.9) (reverse ranked)
in maybe (Left sentence) (Right . snd) found

View File

@ -22,18 +22,18 @@ instance HasModel Model where
getModel = id
setModel = const
ngram_size :: Int
ngram_size = 3
ngramSize :: Int
ngramSize = 3
buildModel :: Text -> Model
buildModel str =
let parts = ngram ngram_size str
let parts = ngram ngramSize str
total = fold parts
in Model{..}
goodness :: Model -> Text -> Double
goodness Model{..} str =
let comparison = M.keys $ ngram ngram_size str
let comparison = M.keys $ ngram ngramSize str
ranksum = getSum $ foldMap (Sum . log . elm) comparison
in ranksum / fromIntegral (length comparison)
where