Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing wildcards for equality in Haskell..?

Tags:

syntax

haskell

In Haskell, is there a way to compare that all wildcards are of the same type and value? For example, I want to create a function that exhibits the following behavior:

(1 M) (2 M) (3 M) -> True
(1 S) (2 S) (3 S) -> True
(1 S) (2 M) (3 S) -> False

In other words, the first parameter should be 1, 2 and 3 and the second parameter should be all S or all M.

In this case, we can maybe write a function as follows:

matches (1 _ ) (2 _ ) (3 _ )

But, how do we determine whether the wildcards are all S or all M?

like image 585
pokiman Avatar asked Jan 23 '23 23:01

pokiman


1 Answers

If the patterns are that simple (all M or all S), why not define it as is?

matches (1, M) (2, M) (3, M) = True
matches (1, S) (2, S) (3, S) = True
matches _ _ _ = False

Or are there other constraints?

like image 165
sykora Avatar answered Jan 29 '23 19:01

sykora