Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can GHC warn about the uses of dangerous non-total functions?

I have been writing quickly some code in Haskell, and used a dangerous non-total function, namely fromJust (where I expect a value from input). I'm going to think later what kind of error-handling style I want to use.

Can GHC help me make sure that I have got rid of all uses of dangerous non-total functions (like fromJust or head, which could crash) , give me warnings where they are.

like image 983
imz -- Ivan Zakharyaschev Avatar asked Mar 05 '15 21:03

imz -- Ivan Zakharyaschev


1 Answers

GHC can warn about definitions with partial patterns with -fwarn-incomplete-patterns (though does not warn about uses of values that include incomplete patterns). Additionally, Neil Mitchell's catch attempts a slightly more detailed analysis to identify safe and unsafe invocations of partial functions. (Though of course that's an undecidable problem in general, so it won't always be right!)

like image 122
Daniel Wagner Avatar answered Oct 15 '22 21:10

Daniel Wagner