danstiner / hfmt

Format Haskell programs. Inspired by the gofmt utility.
MIT License
125 stars 14 forks source link

hfmt.EXE: app\Main.hs:(71,1)-(73,41): Non-exhaustive patterns in function sourceChangedOrHasSuggestions #20

Closed Ciantic closed 6 years ago

Ciantic commented 7 years ago

I'm getting error from HFMT.exe

<interactive>: 29: 20: Parse error: group hfmt.EXE: app\Main.hs:(71,1)-(73,41): Non-exhaustive patterns in function sourceChangedOrHasSuggestions

import Data.List
import Data.Ord

-- | Freq sorting
-- >>> sortByFrequency "amanaplanacanalpanama"
-- "cllmmppnnnnaaaaaaaaaa"
--
-- >>> sortByFrequency ""
-- ""
-- 
sortByFrequency :: Ord a => [a] -> [a]
sortByFrequency xs = 
    let 
        sortedElems = sort xs
        groupped = group sortedElems
        lengthComparsion = comparing (\a -> length a)
        sortedByLength = sortBy lengthComparsion groupped
        joinedStrings = concat sortedByLength
    in
        joinedStrings
Ciantic commented 7 years ago

Also found in another haskell file with a similar problem:

Error reformatting Main.hs: <interactive>: 125: 19: Parse error: x-u hfmt.exe: app\Main.hs:(71,1)-(73,41): Non-exhaustive patterns in function sourceChangedOrHasSuggestions

type PointInSpace = (Float, Float)
(.-) , (.+) :: PointInSpace -> PointInSpace -> PointInSpace
(x,y) .- (u,v) = (x-u,y-v)
(x,y) .+ (u,v) = (x+u,y+v)

It started working when I added spaces (x-u to x - u, ...)

danstiner commented 6 years ago

This should be be fixed in 0.2.0: https://hackage.haskell.org/package/hfmt-0.2.0

Any errors encountered during formatting would previously have run in to that non-exhaustive pattern error, thanks for catching and reporting. Such errors should now be nicely printed out, so if you run into an error again feel free to open a new issue with the hopefully much improved error message.