Skip to content

Commit

Permalink
Stats.headLength: clarify error origin
Browse files Browse the repository at this point in the history
  • Loading branch information
rudymatela committed Jan 25, 2024
1 parent 111bfb8 commit d13c6a5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Test/LeanCheck/Stats.hs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ countsBy (==) = map headLength . classifyBy (==)
-- > > countsOn length ["sheep", "chip", "ship", "cheap", "Mississippi"]
-- > [(5,2),(4,2),(11,1)]
countsOn :: Eq b => (a -> b) -> [a] -> [(b,Int)]
countsOn f = map (\xs -> (f $ head xs, length xs)) . classifyOn f
countsOn f = map (first f . headLength) . classifyOn f
where
first f (x,y) = (f x, y)

countsT :: Eq a => [[a]] -> [(a,Int,[Int])]
countsT xss = [(x,n,map (count x) xss) | (x,n) <- counts (concat xss)]
Expand All @@ -231,7 +233,8 @@ countsTOn :: Eq b => (a -> b) -> [[a]] -> [(b,Int,[Int])]
countsTOn f = countsT . mapT f

headLength :: [a] -> (a,Int)
headLength xs = (head xs, length xs)
headLength [] = (error "Test.LeanCheck.Stats.headLength: empty list", 0)
headLength xs@(x:_) = (x, length xs)

unquote :: String -> String
unquote ('"':s) | last s == '"' = init s
Expand Down

0 comments on commit d13c6a5

Please sign in to comment.