tags:

views:

64

answers:

1

How to declare a function so Listn : ' ' a list -> ' ' a list -> bool, listn xs and ys return true.  

Example: lisen [#"1" #"2"] , [#"1" "#3"] return false and  [#"1" , #"2"] [#"2" , #"1"] return true

A: 

Try this:

infix member
fun x member []         = false
  | x member (y::ys)    = x = y orelse x member ys;

fun listn (x::xs) ys = x member ys andalso listn xs ys
  | listn [] _       = true;
GeorgeWChubby
Your last case of the `listn` function will never be used. If the first argument is not empty, the first case will run (whether the second argument is empty or not). If the first argument is empty the second case will run (also whether the second argument is empty or not).
sepp2k
Thanks mate. My instructor at uni told me to include it, for some reason. Good thing you're here to set him straight ;)
GeorgeWChubby