1

I'm trying to make a function with arguments a and bs, that will check if list bs contains a product whos first element is a. If list bs contains a product whos first element is a, then that product is returned.

The function is giving a nondescriptive error relating to a file "evalloop.sml".

fun matchFirstElement ([], _) = ("V70",["2.4T","V70a1"],(20,25),"MT1") |
matchFirstElement (b::bs, a) = if (a = #1 b) then b else getProdRule(bs, a);
  • The first case says that the result is a list, the `then` of the second that the result has the type of `b`, a pair. The result of a function can't be both a pair and a list. – molbdnilo Mar 30 '18 at 07:57
  • @molbdnilo i was under the impression that [] was a null in this language, how do i return a null/empty value in case of failure? – skullkrusher Mar 31 '18 at 18:15
  • "Null" is not a kind of value as in some other languages. There is a predicate "null", which is true for the empty list (`null []`is true) – i.e. "null" is an adjective, not a noun, just like in English. You want to check out [the `option` type](http://sml-family.org/Basis/option.html#Option:STR:SPEC). – molbdnilo Apr 01 '18 at 08:36
  • I've replaced the returned empty list with a value of the same type as b (see edited question) but im still getting the same error – skullkrusher Apr 01 '18 at 14:45
  • You don't say what `getProdRule` is. Maybe it doesn't have the same return type as `b`? Also, "*The function is giving a nondescriptive error*" is not an error description that leads anywhere. – sshine Apr 03 '18 at 04:49
  • i made a typo there, its solved now thanks. the error was just "Caught error" and then the path to a file called evalloop.sml on my computer... (not a file i made) – skullkrusher Apr 03 '18 at 20:37

0 Answers0