403 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
0
votes
1
answer
56
views
Lean4 Coercion between Nat/ Fin3/Fin9 with simp tactic pass the proof of 0=2 [closed]
example (i:Fin 9)(h:(i.1/3 :Fin 3).1 = i/3): 0 = i.1/3:= by
simp at h
exact h
This finishes the proof, but
if i = 6, then h certainly is true. But the claim is 0 = i.1/3 <=> 0 = 2
either ...
4
votes
3
answers
101
views
"12"+ {"x":"1",toString(){return 10;},valueOf(){return 90}}; evaluate the above expression in JavaScript
console.log("12"+ {"x":"1",toString(){return 10;},valueOf(){return 90}});
In the above expression why toString() method is not called? As per the algorithm if either the left or right side there ...
9
votes
1
answer
146
views
Why can the keyword "end" be passed into a function handle in MATLAB without throwing an error?
Consider the minimally reproducible example:
f = @(x) x
f(end)
Note, the MATLAB syntax highlighter doesn't actually highlight end in blue, showing that it is not parsing as a keyword, even though the ...
0
votes
1
answer
629
views
What does Rust error "you could box the found value and coerce it to the trait object" mean?
What does this error mean?
Reproduction
error[E0308]: mismatched types
--> src/main.rs:50:35
|
50 | PaymentType::InvoiceIn => InvoiceIn {
| ___________________________________^...
3
votes
1
answer
75
views
How get an immutable Pin from a mutable Pin?
How to apply deref coercion from &mut to & for references that are wrapped inside Pin<>? That is, how to borrow Pin<&mut _> as Pin<&_>?
use std::pin::{Pin, pin};
fn ...
0
votes
1
answer
103
views
How does Dereferencing with Traits and Trait functions with Slices and Arrays work
(I am new to rust and trying to write a little card game as an exercise and I might not have grasped some things correctly. I am trying to break down my problem/confusion as much as I can.)
I want to ...
0
votes
2
answers
135
views
In R, how do you change the class of data in a matrix?
Say you have a matrix of logical values of size 6x4:
set.seed(4)
mat <- matrix(sample(c(T, F), 24, replace = T), ncol = 4)
mat
# [,1] [,2] [,3] [,4]
# [1,] FALSE TRUE FALSE FALSE
# [2,] ...
4
votes
2
answers
90
views
Admissble type role overrides
In GHC Haskell, Map k v has a type role declaration for k to be nominal. This is because the user can otherwise coerce k to another type with the same representation but different Ord instance, ...
0
votes
0
answers
61
views
Equivalent Casting of JPEG to Data, but with .mov files in Swift
I have some code that works fine, using Amplify to push and pull images from an AWS-S3 bucket.
let uploadTask = Amplify.Storage.uploadData(key: imageKey, data: srcData, options: nil)
Task {
...
0
votes
0
answers
80
views
Is there a Rust signature signaling that any type that coerces into T would be allowed? [duplicate]
So I just started learning about Rust and the Implicit Deref Coercion. A "problem" I now often tumble over, is that this automatic deref does not work inside of other types, e.g. as Item ...
2
votes
0
answers
256
views
Specify in Rust that a generic type supports coercion to a primitive type
In Rust, I have several different enums that are all #[repr(u32)], meaning I can use as to cast them to a u32:
#[repr(u32)]
enum Foo {A, B, C}
fn f(foo: Foo) {
dbg!(foo as u32);
}
Now I want to ...
0
votes
1
answer
470
views
ToPrimitive VS OrdinaryToPrimitive
I am reading the Book, YDKJS by Kyle Simpson, topic Coercion. While looking at the specs I found that ToPrimitive calls OrdinaryToPrimitive conditionally. I read in a blog that:
JavaScript view ...
2
votes
1
answer
192
views
Why do I need to use `&` to trigger deref coercion in rust?
From The Rust Programming Language book:
Deref coercion converts a reference to a type that implements the
Deref trait into reference to another type
Questions in code snippet below:
Why & is ...
4
votes
1
answer
489
views
Why do I need to implement `From` for both a value and a reference? Shouldn't methods be automatically dereferenced or borrowed?
The behaviour of a Rust method call is described in The Rust Reference. It states that "when looking up a method call, the receiver may be automatically dereferenced or borrowed in order to call ...
0
votes
0
answers
285
views
TS: Conditional property based on the value of a generic
Here I have a stripped down code snippet to demonstrate the sort of thing I'm trying to achieve:
interface A<RequiresB extends boolean = true> {
alwaysRequired: string
b: RequiresB extends ...