COMPLETE pragma for MonthOfYear type is questionable.
phadej opened this issue · comments
Oleg Grenrus commented
An example:
{-# OPTIONS_GHC -Wall #-}
import Data.Time.Calendar
ex1 :: Int -> Bool
ex1 1 = True
ex1 2 = True
ex1 3 = True
ex1 4 = True
ex1 5 = True
ex1 6 = True
ex1 7 = True
ex1 8 = True
ex1 9 = True
ex1 10 = True
ex1 11 = True
ex1 12 = True
ex2 :: Int -> Bool
ex2 January = True
ex2 February = True
ex2 March = True
ex2 April = True
ex2 May = True
ex2 June = True
ex2 July = True
ex2 August = True
ex2 September = True
ex2 October = True
ex2 November = True
ex2 December = True
Warns about ex1 but not about ex2:
Questionable.hs:5:1: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In an equation for ‘ex1’:
Patterns not matched:
p where p is not one of {12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}
|
5 | ex1 1 = True
| ^^^^^^^^^^^^...
as type MonthOfYear = Int
this is very questionable. Pattern synonyms itself are fine, but claiming that they are complete for Int
, without any help even from a newtype wrapper is IMHO not a good idea.
Ashley Yakeley commented
This is intended behaviour.
Oleg Grenrus commented
I don't agree this is great, as MonthOfYear
is just Int
and there is no (new)type safety net to track provenance of the values, but I won't insist.
Tom Sydney Kerckhove commented
Intended as this may be be, I don't agree it's great either and just wanted to record that here.