Type-driven linting

Let’s say I want to remove the use of fromRational :: Rational -> Scientific, which is partial. Hlint can’t do it, because it doesn’t know about types. Is there maybe a GHC plugin driven linter that would be able be able to warn me about uses of this function instantiated like this?

3 Likes

I presume stan: Haskell STatic ANalyser can do it.

2 Likes

Yes, stan can do that. Have a look here for examples of similar rules: stan/src/Stan/Inspection/Partial.hs at 3bbddb044af80133ae9a1de270323f3defcc7fce · kowainik/stan · GitHub

3 Likes

We started using stan (thanks to my colleague) but it’s inadequate since there is nothing stopping us from using the partial type classes indirectly, e.g. through Hedgehog:

% cabal repl -b hedgehog -b scientific
ghci> :m +Hedgehog Hedgehog.Range Hedgehog.Gen Data.Scientific
ghci> sample ( realFrac_ (linearFracFrom 99 (99 :: Scientific) 99 ))
*** Exception: fromRational has been applied to a repeating decimal