From 7c8a298f71bd0cbf2872cc68685ac748c2c17966 Mon Sep 17 00:00:00 2001 From: Mats Rauhala Date: Tue, 15 Oct 2019 23:13:34 +0300 Subject: [PATCH] Hlint fixes --- src/API.hs | 3 +-- src/Data/Language.hs | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/API.hs b/src/API.hs index 61be95e..2a861b1 100644 --- a/src/API.hs +++ b/src/API.hs @@ -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 diff --git a/src/Data/Language.hs b/src/Data/Language.hs index 7bb0be5..e0a2542 100644 --- a/src/Data/Language.hs +++ b/src/Data/Language.hs @@ -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