Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get warnings about overly-restrictive type signatures?

Tags:

haskell

ghc

Can GHC or some lint tool tell me when I've provided a type signature for a function that could be more polymorphic?

like image 823
jberryman Avatar asked Apr 03 '12 02:04

jberryman


1 Answers

GHC doesn't do this, and a quick search of Hackage turns up nothing.

A simple, but possibly quite effective way to implement such a thing would be to load the module in GHCi, use :browse to get all the type signatures, then load a copy without any type signatures, use :browse again, and compare the two outputs; then just print all the lines that differ beyond parentheses, whitespace and alpha-renaming. However, this wouldn't work perfectly, especially if you have definitions whose types can't be inferred.

I have a feeling such a tool would turn up a lot of false positives in practice.

like image 69
ehird Avatar answered Nov 13 '22 03:11

ehird