Difference between revisions of "Mutable List Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
Line 1: Line 1:
 
=Code to Implement=
 
=Code to Implement=
==create_mutable_list_from_immutable_list==
+
==types==
  fun create_mutable_list_from_immutable_list(xs) : 'a mutable_list =
+
  <nowiki>(* TODO: replace unit with the datatype/type synonym(s) you decide upon *)
    raise NotYetImplemented
+
type 'a mutable_list = unit</nowiki>
==create_empty_mutable_list==
 
fun create_empty_mutable_list() : 'a mutable_list =  
 
    raise NotYetImplemented
 
  
==create_mutable_list_from_other_mutable_list==
+
==functions==
  fun create_mutable_list_from_other_mutable_list(ml) : 'a mutable_list =  
+
<nowiki>val construct_empty = fn : unit -> 'a mutable_list
     raise NotYetImplemented
+
val length = fn : 'a mutable_list -> int
 +
val clear = fn : 'a mutable_list -> unit
 +
val add_to_front = fn : 'a mutable_list * 'a -> unit
 +
val add_to_back = fn : 'a mutable_list * 'a -> unit
 +
val contains = fn : ('a -> bool) * 'a mutable_list -> bool
 +
val nth = fn : 'a mutable_list * int -> 'a
 +
val construct_from_immutable = fn : 'a list -> 'a mutable_list
 +
val foldl = fn : ('a * 'b -> 'b) * 'b * 'a mutable_list -> 'b
 +
val to_immutable = fn : 'a mutable_list -> 'a list
 +
val map = fn : ('a -> 'b) * 'a mutable_list -> 'b mutable_list
 +
val copy = fn : 'a mutable_list -> 'a mutable_list
 +
val @ = fn : 'a mutable_list * 'a mutable_list -> 'a mutable_list
 +
val reverse = fn : 'a mutable_list -> unit</nowiki>
 +
 
 +
==construct_empty==
 +
  fun construct_empty() : 'a mutable_list =  
 +
     raise Fail "NotYetImplemented"
  
==to_immutable==
 
fun to_immutable(ml : 'a mutable_list) : 'a list =
 
    raise NotYetImplemented
 
  
 
==length==
 
==length==
  fun length(ml : 'a mutable_list) : int =
+
  fun length(mlist : 'a mutable_list) : int =  
     raise NotYetImplemented
+
     raise Fail "NotYetImplemented"
 +
 
 +
==clear==
 +
fun clear(mlist : 'a mutable_list) : unit =
 +
    raise Fail "NotYetImplemented"
 +
 
 +
==add_to_front==
 +
fun add_to_front(mlist : 'a mutable_list, value : 'a) : unit =
 +
    raise Fail "NotYetImplemented"
  
==insert_at_front==
+
==add_to_back==
  fun insert_at_front(ml : 'a mutable_list, item : 'a) : unit =
+
  fun add_to_back(mlist : 'a mutable_list, value : 'a) : unit =
     raise NotYetImplemented
+
     raise Fail "NotYetImplemented"
  
==insert_at_back==
+
==contains==
  fun insert_at_back(ml : 'a mutable_list, item : 'a) : unit =
+
  fun contains(predicate : ('a -> bool), mlist : 'a mutable_list) : bool =
     raise NotYetImplemented
+
     raise Fail "NotYetImplemented"
  
==remove_first_match==
+
==nth==
  <nowiki>fun remove_first_match(ml : ''a mutable_list, item : ''a) : bool =
+
  (* raise Subscript if out of bounds *)
     raise NotYetImplemented</nowiki>
+
fun nth(mlist : 'a mutable_list, index : int) : 'a =  
 +
     raise Fail "NotYetImplemented"
  
==concat==
+
==construct_from_immutable==
  fun concat(a : 'a mutable_list, b : 'a mutable_list) : unit =  
+
  fun construct_from_immutable(values : 'a list) : 'a mutable_list =  
     raise NotYetImplemented
+
     raise Fail "NotYetImplemented"
  
==reverse==
+
==foldl==
  fun reverse(ml : 'a mutable_list) : unit =
+
  fun foldl(f : ('a * 'b -> 'b), init : 'b, mlist : 'a mutable_list) : 'b =
     raise NotYetImplemented
+
    raise Fail "NotYetImplemented"
 +
 
 +
==to_immutable==
 +
fun to_immutable(mlist : 'a mutable_list) : 'a list =  
 +
     raise Fail "NotYetImplemented"

Revision as of 08:52, 21 February 2022

Code to Implement

types

(* TODO: replace unit with the datatype/type synonym(s) you decide upon *)
type 'a mutable_list = unit

functions

val construct_empty = fn : unit -> 'a mutable_list
val length = fn : 'a mutable_list -> int
val clear = fn : 'a mutable_list -> unit
val add_to_front = fn : 'a mutable_list * 'a -> unit
val add_to_back = fn : 'a mutable_list * 'a -> unit
val contains = fn : ('a -> bool) * 'a mutable_list -> bool
val nth = fn : 'a mutable_list * int -> 'a
val construct_from_immutable = fn : 'a list -> 'a mutable_list
val foldl = fn : ('a * 'b -> 'b) * 'b * 'a mutable_list -> 'b
val to_immutable = fn : 'a mutable_list -> 'a list
val map = fn : ('a -> 'b) * 'a mutable_list -> 'b mutable_list
val copy = fn : 'a mutable_list -> 'a mutable_list
val @ = fn : 'a mutable_list * 'a mutable_list -> 'a mutable_list
val reverse = fn : 'a mutable_list -> unit

construct_empty

fun construct_empty() : 'a mutable_list = 
   raise Fail "NotYetImplemented"


length

fun length(mlist : 'a mutable_list) : int = 
   raise Fail "NotYetImplemented"

clear

fun clear(mlist : 'a mutable_list) : unit =
   raise Fail "NotYetImplemented"

add_to_front

fun add_to_front(mlist : 'a mutable_list, value : 'a) : unit =
   raise Fail "NotYetImplemented"

add_to_back

fun add_to_back(mlist : 'a mutable_list, value : 'a) : unit =
   raise Fail "NotYetImplemented"

contains

fun contains(predicate : ('a -> bool), mlist : 'a mutable_list) : bool =
   raise Fail "NotYetImplemented"

nth

(* raise Subscript if out of bounds *)

fun nth(mlist : 'a mutable_list, index : int) : 'a =

   raise Fail "NotYetImplemented"

construct_from_immutable

fun construct_from_immutable(values : 'a list) : 'a mutable_list = 
   raise Fail "NotYetImplemented"

foldl

fun foldl(f : ('a * 'b -> 'b), init : 'b, mlist : 'a mutable_list) : 'b = 
   raise Fail "NotYetImplemented"

to_immutable

fun to_immutable(mlist : 'a mutable_list) : 'a list = 
   raise Fail "NotYetImplemented"