Difference between revisions of "Mutable List Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
Line 4: Line 4:
 
type 'a mutable_list = unit</nowiki>
 
type 'a mutable_list = unit</nowiki>
  
==functions==
+
==signatures==
 
  <nowiki>val construct_empty = fn : unit -> 'a mutable_list
 
  <nowiki>val construct_empty = fn : unit -> 'a mutable_list
 
val length = fn : 'a mutable_list -> int
 
val length = fn : 'a mutable_list -> int
Line 23: Line 23:
 
  fun construct_empty() : 'a mutable_list =  
 
  fun construct_empty() : 'a mutable_list =  
 
     raise Fail "NotYetImplemented"
 
     raise Fail "NotYetImplemented"
 
  
 
==length==
 
==length==
Line 38: Line 37:
 
  fun add_to_front(mlist : 'a mutable_list, value : 'a) : unit =
 
  fun add_to_front(mlist : 'a mutable_list, value : 'a) : unit =
 
     raise Fail "NotYetImplemented"
 
     raise Fail "NotYetImplemented"
 +
 +
Analogous to [https://smlfamily.github.io/Basis/list.html#SIG:LIST.:::TY ::].
  
 
==add_to_back==
 
==add_to_back==
Line 48: Line 49:
  
 
==nth==
 
==nth==
  <nowiki>(* raise Subscript if out of bounds *)
+
  <nowiki>fun nth(mlist : 'a mutable_list, index : int) : 'a =  
fun nth(mlist : 'a mutable_list, index : int) : 'a =  
 
 
     raise Fail "NotYetImplemented"</nowiki>
 
     raise Fail "NotYetImplemented"</nowiki>
 +
 +
Analogous to [https://smlfamily.github.io/Basis/list.html#SIG:LIST.nth:VAL List.nth].
 +
 +
Note: raise [https://smlfamily.github.io/Basis/general.html#SIG:GENERAL.Subscript:EXN:SPEC Subscript] if out of bounds.
  
 
==construct_from_immutable==
 
==construct_from_immutable==
Line 59: Line 63:
 
  fun foldl(f : ('a * 'b -> 'b), init : 'b, mlist : 'a mutable_list) : 'b =  
 
  fun foldl(f : ('a * 'b -> 'b), init : 'b, mlist : 'a mutable_list) : 'b =  
 
     raise Fail "NotYetImplemented"
 
     raise Fail "NotYetImplemented"
 +
 +
Analogous to [https://smlfamily.github.io/Basis/list.html#SIG:LIST.foldl:VAL List.foldl].
  
 
==to_immutable==
 
==to_immutable==
Line 67: Line 73:
 
  fun map(f : ('a -> 'b), mlist : 'a mutable_list) : 'b mutable_list =
 
  fun map(f : ('a -> 'b), mlist : 'a mutable_list) : 'b mutable_list =
 
     raise Fail "NotYetImplemented"
 
     raise Fail "NotYetImplemented"
 +
 +
Analogous to [https://smlfamily.github.io/Basis/list.html#SIG:LIST.map:VAL List.map].
  
 
==copy==
 
==copy==
Line 75: Line 83:
 
  fun a @ b =  
 
  fun a @ b =  
 
     raise Fail "NotYetImplemented"
 
     raise Fail "NotYetImplemented"
 +
 +
Analogous to [https://smlfamily.github.io/Basis/list.html#SIG:LIST.@:VAL List.@].
 +
 +
Note: does NOT alias.
  
 
==reverse==
 
==reverse==
 
  fun reverse(mlist : 'a mutable_list) : unit =
 
  fun reverse(mlist : 'a mutable_list) : unit =
 
     raise Fail "NotYetImplemented"
 
     raise Fail "NotYetImplemented"
 +
 +
Analogous to [https://smlfamily.github.io/Basis/list.html#SIG:LIST.rev:VAL List.rev]
 +
 +
=Testing=

Revision as of 09:03, 21 February 2022

Code to Implement

types

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

signatures

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"

Analogous to List.length.

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"

Analogous to ::.

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

fun nth(mlist : 'a mutable_list, index : int) : 'a = 
    raise Fail "NotYetImplemented"

Analogous to List.nth.

Note: raise Subscript if out of bounds.

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"

Analogous to List.foldl.

to_immutable

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

map

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

Analogous to List.map.

copy

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

@

fun a @ b = 
   raise Fail "NotYetImplemented"

Analogous to List.@.

Note: does NOT alias.

reverse

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

Analogous to List.rev

Testing