Incomplete patterns

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Incomplete patterns

Jona Ekenberg
Hello,

I am currently going through the CIS194 spring 13 course, since it has been recommended by several haskellions. I find the exercises extremely valuable, and the reading material is succinct (in a good way).

I just finished the exercises for lesson two, and while everything works, I get this warning:
Lektion02.hs:(38,1)-(44,21): warning: [-Wincomplete-patterns] …
    Pattern match(es) are non-exhaustive
    In an equation for ‘insert’:
        Patterns not matched:
            (LogMessage _ _ _) (Node _ (LogMessage _ _ _) _)

I understand that there is a pattern I'm not covering, but I can't really figure out which one. Here is my function:
insert :: LogMessage -> MessageTree -> MessageTree
insert (Unknown _) mt  = mt
insert m Leaf          = Node Leaf m Leaf
insert m@(LogMessage _ t _) (Node left value@(LogMessage _ t' _) right)
  | t <= t' = Node (insert m left) value right
  | t >  t' = Node left            value (insert m right)
insert m@(LogMessage _ _ _) (Node left (Unknown _) right)
  = Node left m right

(here's a pastebin with intact indentation: http://lpaste.net/356716)

I am not sure on how I should progress to find out which pattern I'm missing.
Any help is appreciated.

Kind regards,
Jona

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Incomplete patterns

Sylvain Henry-2
Hi,

In the following code:

insert m@(LogMessage _ t _) (Node left value@(LogMessage _ t' _) right)
  | t <= t' = Node (insert m left) value right
  | t >  t' = Node left            value (insert m right)

GHC can't detect that both guards (t <= t') and (t > t') cover all cases. The usual way to deal with this is to use "otherwise" (which is always true):

insert m@(LogMessage _ t _) (Node left value@(LogMessage _ t' _) right)
  | t <= t'       = Node (insert m left) value right
  | otherwise = Node left            value (insert m right)

Regards,
Sylvain

On 06/07/2017 11:12, Jona Ekenberg wrote:
Hello,

I am currently going through the CIS194 spring 13 course, since it has been recommended by several haskellions. I find the exercises extremely valuable, and the reading material is succinct (in a good way).

I just finished the exercises for lesson two, and while everything works, I get this warning:
Lektion02.hs:(38,1)-(44,21): warning: [-Wincomplete-patterns] …
    Pattern match(es) are non-exhaustive
    In an equation for ‘insert’:
        Patterns not matched:
            (LogMessage _ _ _) (Node _ (LogMessage _ _ _) _)

I understand that there is a pattern I'm not covering, but I can't really figure out which one. Here is my function:
insert :: LogMessage -> MessageTree -> MessageTree
insert (Unknown _) mt  = mt
insert m Leaf          = Node Leaf m Leaf
insert m@(LogMessage _ t _) (Node left value@(LogMessage _ t' _) right)
  | t <= t' = Node (insert m left) value right
  | t >  t' = Node left            value (insert m right)
insert m@(LogMessage _ _ _) (Node left (Unknown _) right)
  = Node left m right

(here's a pastebin with intact indentation: http://lpaste.net/356716)

I am not sure on how I should progress to find out which pattern I'm missing.
Any help is appreciated.

Kind regards,
Jona


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Loading...