[Haskell-cafe] OverloadedLists pattern-matching
k-bx at k-bx.com
Sun Apr 13 14:08:30 UTC 2014
Thanks, you and Roman are right.
On Sun, Apr 13, 2014 at 2:48 PM, Oliver Charles <ollie at ocharles.org.uk>wrote:
> On Sun, Apr 13, 2014 at 12:24 PM, Roman Cheplyaka <roma at ro-che.info>
> > * Konstantine Rybnikov <k-bx at k-bx.com> [2014-04-13 12:21:44+0200]
> >> Just FYI, this still gives a warning:
> >> ...
> >> case m of
> >>  -> putStrLn "empty"
> >> (M.toList -> (x:_)) -> putStrLn $ "ok, some random elem is: " ++
> show x
> > Does that surprise you? The compiler doesn't have any special knowledge
> > the M.toList function to infer that these two cases are exhaustive.
> Roman is right, and I think it's clearer if you consider this without view
> case m of
>  -> ...
> m' -> case M.toList m' of
> (x : _) -> ...
> Looking at this, it's clear that the patterns are not exhaustive - you
> didn't match the scenario that M.toList m' produced an empty list.
> *You* know that M.toList (M.fromList ) == , but GHC doesn't - and I
> think this is where the problem lies. With that information you might be
> able to have exhaustive pattern matches there.
> - ocharles
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe