mlworks icon indicating copy to clipboard operation
mlworks copied to clipboard

RealArray in functor

Open ellerh opened this issue 9 years ago • 3 comments

This example

functor Foo (val update : RealArray.array * int * real -> unit) =
  struct
    val foo = update
  end

structure Foo = Foo (val update = RealArray.update);

val a = RealArray.array (3, 2.0)
val _ = (Foo.foo (a, 1, 1.0);
       if Real.== (RealArray.sub (a, 1),  1.0) then print "OK\n"
       else print ("WRONG (" ^ Real.toString (RealArray.sub (a, 1)) ^ ")\n"))

when executed with: mlworks -tty -no-init < test.sml prints

MLWorks 2.1 Professional Edition
Copyright (C) 1999 Harlequin Group plc.  All rights reserved.
MLWorks is a trademark of Harlequin Group plc.

MLWorks> MLWorks>> MLWorks>> MLWorks>> MLWorks>> MLWorks>> functor Foo
structure Foo =
  struct
    val foo : (RealArray.array * int * real) -> unit = fn
  end
MLWorks> MLWorks> MLWorks>> MLWorks>> MLWorks>> MLWorks>> WRONG (7.9892357038E~312)
val a : RealArray.array = #F[2.0, 7.989235704E~312, 2.0]

the expected result is of course #F[2.0, 1.0, 2.0]

ellerh avatar Jan 09 '16 17:01 ellerh

At 2016-01-09 17:47:38, Helmut Eller [email protected] wrote:

This example

functor Foo (val update : RealArrayarray * int * real -> unit) = struct val foo = update end

structure Foo = Foo (val update = RealArrayupdate);

val a = RealArrayarray (3, 20) val _ = (Foofoo (a, 1, 10); if Real== (RealArraysub (a, 1), 10) then print "OK\n" else print ("WRONG (" ^ RealtoString (RealArraysub (a, 1)) ^ ")\n"))

when executed with: mlworks -tty -no-init < testsml prints

MLWorks 21 Professional Edition Copyright (C) 1999 Harlequin Group plc All rights reserved MLWorks is a trademark of Harlequin Group plc

MLWorks> MLWorks>> MLWorks>> MLWorks>> MLWorks>> MLWorks>> functor Foo structure Foo = struct val foo : (RealArrayarray * int * real) -> unit = fn end MLWorks> MLWorks> MLWorks>> MLWorks>> MLWorks>> MLWorks>> WRONG (79892357038E~312) val a : RealArrayarray = #F[20, 7989235704E~312, 20]

the expected result is of course #F[20, 10, 20]

— Reply to this email directly or view it on GitHub.

Calling conventions, eh? Hmm. I bet this is a boxing/unboxing issue.

By the way, I don’t know whether we can make GitHub stop stripping periods out of bug reports when turning them into email. It’s really annoying.

Nick B

NickBarnes avatar Jan 10 '16 13:01 NickBarnes

Does this work if you write a my_update() function which explicitly calls RealArray.update, and give that to the functor? If so, that bolsters my suspicion of a boxing bug.

NickBarnes avatar Jan 10 '16 13:01 NickBarnes

Does this work if you write a my_update() function which explicitly calls RealArray.update, and give that to the functor? If so, that bolsters my suspicion of a boxing bug.

Yes, with structure Foo = Foo (val update = fn (a, x, i) => RealArray.update (a, x, i)) things work as they should.

ellerh avatar Jan 10 '16 15:01 ellerh