This is what I have, issue is it creates two copies of width / height / data
[<AbstractClass>]
type IImage<'T when 'T : struct> (width, height, data : 'T[]) =
let mutable width = width
let mutable height = height
let mutable data = data
type Image public (width, height, data : double[]) =
inherit IImage<double>(width, height, data)
This is what I want (C#) and actually thought I was doing
public abstract class IImage<T>
where T : struct
{
public IImage(int width, int height, T[] data)
{
if (data.Length != width * height)
{
throw new ArgumentException();
}
this._width = width;
this._height = height;
this._data = data;
}
}
public class Image : IImage<double>
{
public Image(int width, int height, double[] data)
: base(width, height, data)
{
}
}
width, height, data need to be protected in C# speak
I tried inherit without arguments with a new() = {..} but that does not want to compile
Also I am not sure who what this is called and how this is done in F# (I implemented it as this.At with get() currently)
public T this[int i, int j]
Also one horrible moronic limitation of C# is the inability to have a generic which supports + - / * (double, float, int32, uint32, int64, decimal, etc)
which forces a lot of functions to be abstract, or cast to dynamic
but when I constrain 'T a bit
'T when 'T : struct and 'T : (static member (+) : 'T -> 'T)
this (rewritten from C# private IImage<T> _map(Func<int, T> _func, bool _parallel))
member this.baseMap ((func: int -> 'T), (concurrent : Option<bool>)) =
if istrue concurrent then
Parallel.For (0, data.Length, (fun i -> data.[i] <- func i))
|> ignore
else
for i in 0 .. data.Length - 1 do
data.[i] <- (func i)
gives,
This code is not sufficiently generic. The type variable ^T when ^T : struct and ^T : (static member ( + ) : ^T -> ^T)
Question
+Red King Subscriber²
This is what I have, issue is it creates two copies of width / height / data
I tried inherit without arguments with a new() = {..} but that does not want to compile
Also I am not sure who what this is called and how this is done in F# (I implemented it as this.At with get() currently)
which forces a lot of functions to be abstract, or cast to dynamic
but when I constrain 'T a bit
this (rewritten from C# private IImage<T> _map(Func<int, T> _func, bool _parallel)) gives,Link to comment
Share on other sites
6 answers to this question
Recommended Posts