Skip to main content

I'd like to know if there is any way to create a function that, given a list of namesnames/identifiersidentifiers e.g. [Monday, Tuesday, ...][Monday, Tuesday, ...], automatically creates a datatype day = Monday | Tuesday | ...datatype day = Monday | Tuesday | ... and a function next such that next Monday = Tuesdaynext Monday = Tuesday, next Tuesday = Wednesdaynext Tuesday = Wednesday, ... preserving (and reflecting) the order of the identifiers in the list. I know I can do this by hand, but I was wondering if datatype declarations are even possible within functions. If this isn't possible in SML, what are some languages (preferably functional) that allow this?

I'd like to know if there is any way to create a function that, given a list of names/identifiers e.g. [Monday, Tuesday, ...], automatically creates a datatype day = Monday | Tuesday | ... and a function next such that next Monday = Tuesday, next Tuesday = Wednesday, ... preserving (and reflecting) the order of the identifiers in the list. I know I can do this by hand, but I was wondering if datatype declarations are even possible within functions. If this isn't possible in SML, what are some languages (preferably functional) that allow this?

I'd like to know if there is any way to create a function that, given a list of names/identifiers e.g. [Monday, Tuesday, ...], automatically creates a datatype day = Monday | Tuesday | ... and a function next such that next Monday = Tuesday, next Tuesday = Wednesday, ... preserving (and reflecting) the order of the identifiers in the list. I know I can do this by hand, but I was wondering if datatype declarations are even possible within functions. If this isn't possible in SML, what are some languages (preferably functional) that allow this?

edited tags
Link
John Coleman
  • 52.1k
  • 7
  • 59
  • 127
Source Link
Gepapado
  • 353
  • 2
  • 5
  • 11

How to construct ordered datatypes in SML automatically

I'd like to know if there is any way to create a function that, given a list of names/identifiers e.g. [Monday, Tuesday, ...], automatically creates a datatype day = Monday | Tuesday | ... and a function next such that next Monday = Tuesday, next Tuesday = Wednesday, ... preserving (and reflecting) the order of the identifiers in the list. I know I can do this by hand, but I was wondering if datatype declarations are even possible within functions. If this isn't possible in SML, what are some languages (preferably functional) that allow this?