Fable: inconsistencies with arrays

Created on 2 Aug 2018  路  9Comments  路  Source: fable-compiler/Fable

Description

I would expect arrays to behave consistently regardless of whether they are emitted or written in F#

Repro code

[<Emit(" [1] ")>]
let arr : int []  = jsNative

[|1|] = [|1|] // is true
arr = [|1|] // is false

Expected and actual results

I'd expect both to have the same result. JS semantics would result in false whereas F# semantics would make both true. I would suggest the latter

Related information

using docker image: nojaf/fable:latest

Most helpful comment

@Zaid-Ajaj Sshh, it's a secret :wink: Yes, repl2 is working and it features several of your Elmish samples. It'll be announced shortly :+1: Glad you like it!

All 9 comments

F# use TypedArray when possible to improve performance.

open Fable.Core
open Fable.Core.JsInterop
open Fable.Import

[<Emit(" [1] ")>]
let arr () : int []  = jsNative

JS.console.log([|1|] = [|1|]) // is true
JS.console.log(arr () = [|1|]) // is false

Generated JS:

import { equals } from "fable-core/Util";
console.log(equals(new Int32Array([1]), new Int32Array([1])));
console.log(equals([1], new Int32Array([1])));

@alfonsogarciacaro Daaamn repl2 is already working? and with elmish samples too, talk about next level fancy stuff, this is amazing :heart:

@Zaid-Ajaj Sshh, it's a secret :wink: Yes, repl2 is working and it features several of your Elmish samples. It'll be announced shortly :+1: Glad you like it!

@alfonsogarciacaro Only here to tell you that the repl is indeed awesome! (just one minor nit I noticed while using no-script blocking nupkg.com: The error reporting could be a bit better)

@matthid Sorry, do you mean when JS is disabled in the browser? How would you show the error in that case, with an HTML tag? Could you please send a PR for that?

Seems like I cannot reproduce anymore but I had this configuration:
image
and the samples stayed blank. You probably can ignore me as noscript is really uncommon nowadays. Anyway it seems blocking the script no longer works and my browser/the extension is not doing what I want. So now it always works...

when I closed and the page refreshed I could see the discussion had continued. With the Int32Array comment I find the behavior to be consistent. I emitted a different type of object than what I should have expected fable to compile to. However since you continued the discussion. I'd leave it up to you whether it should be closed

Thanks for confirming @runefs. Ok, let's close this and continue the discussion if necessary in the repl2 repo :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jwosty picture jwosty  路  3Comments

MangelMaxime picture MangelMaxime  路  3Comments

ncave picture ncave  路  3Comments

SirUppyPancakes picture SirUppyPancakes  路  3Comments

forki picture forki  路  3Comments