I am writing a library for processing simple images in standard ML. It must support the various types used as the color for each pixel, for example. bool, Word8.word, etc.
I have abstype 'a imagewith all the common functions defined independently of the view ( 'a- this is the color view), but the output formats are different, so I would like to have different structures.
Is there a way to “open” abstypeinside a structure? I can make this work very ugly:
abstype 'clr absimage = Image of {width : int, height : int, data : 'clr array array}
with
fun createFunc (w, h) f = Image {width = w, height = h, data = ...}
fun createBlank (w, h) clr = createFunc (w, h) (fn _ => clr)
...
end
signature IMAGE = sig
type colour
type image
val createFunc : (int * int) -> (int * int -> colour) -> image
val createBlank : (int * int) -> colour -> image
...
val toBinPPM : image -> string -> unit
end
functor ImageFn(C : sig type colour end) = struct
open C
type image = colour absimage
val createFunc = createFunc
val createBlank = createBlank
...
end
structure Image8 :> IMAGE = struct
structure T = ImageFn(struct type colour = Word8.word end)
open T
fun toBinPPM img filename = ...
end
In particular, to define a functor, it is required to write expressions such as val name = namefor all functions defined in the with ... endpart abstype.
Or is my approach completely wrong?
abstype signature - OOP abstype signature
P.S. SML , open (ImageFn(struct ... end)), (T )?