Search code examples
smlmlmosml

Wrapping Datatypes in Standard ML


This question is a follow up question to the question posted here:

Understanding user defined append list Standard ml

The problem I am running into is that I can't seem to figure out how to properly wrap the Append Node within the NonNil correctly. The code I have is:

fun alistAppend (xs: 'a alist, ys: 'a alist): 'a alist = 
    case xs of
    Nil => ys
   | _ =>  NonNil (Append (xs,ys));

I know this code may not append correctly, I'm simply trying to figure out how to get the correct return type for this function. What is the proper way to wrap the Append Node?


Solution

  • Was able to figure it out, by creating a new val:

    val paired = (xs ,ys); 
    

    I was able to check the value of both xs and ys at the same time. Simply have to check if both xs and ys are NonNil, then make the appropriate Append Node within a NotNil node.