cpd1
cpd1

Reputation: 789

SML NJ - match nonexhausitive - not sure how to handle

I want to define a function that takes 3 parameters and returns a list. The parameters will be of any type and then other two parameters are of lists of any types. This is an example...

fun func x [y] [z] = [x, y, z];

Even though the function evaluates to the proper data types, I get a match non-exhaustive warning.

In this example, I don't get the same warning...

fun func x y = (y, x);

It should be because of the lists but I'm not sure how to handle it so I don't actually see a warning.

Upvotes: 0

Views: 34

Answers (1)

John Coleman
John Coleman

Reputation: 51998

You are getting that warning because you have only told your function what to do when passed an element and two lists, where each of the lists has only 1-element. What happens if one or both of those lists have fewer than 1 or more than 1 element?

Are you familiar with @? It might help you write the function that you seem intent on writing, but without that warning.

Upvotes: 1

Related Questions