guid¶
In [ ]:
//// test
open testing
guid¶
guid¶
In [ ]:
nominal guid_python =
`(
global "import uuid"
$'' : $'uuid.UUID'
)
type guid_switch =
{
Fsharp : $'System.Guid'
Python : guid_python
}
nominal guid = $'backend_switch `(guid_switch)'
new_guid¶
In [ ]:
inl new_guid (x : string) : guid =
run_target_args (fun () => x) function
| Rust (Contract) => fun _ => null ()
| _ => fun x => x |> convert
new_raw_guid¶
In [ ]:
inl new_raw_guid () : guid =
backend_switch {
Fsharp = fun () => $'System.Guid.NewGuid' () : guid
Python = fun () => $'uuid.uuid4()' : guid
}
hash_guid¶
In [ ]:
type hash_guid = guid
let hash_guid (hash : string) : hash_guid =
run_target_args (fun () => hash) function
| Rust (Contract) => fun _ => null ()
| _ => fun hash =>
inl hash = hash |> sm'.pad_left 32i32 '0'
inl a = hash |> sm'.range (am'.Start 0i32) (am'.End fun _ => 8)
inl b = hash |> sm'.range (am'.Start 8i32) (am'.End fun _ => 12)
inl c = hash |> sm'.range (am'.Start 12i32) (am'.End fun _ => 16)
inl d = hash |> sm'.range (am'.Start 16i32) (am'.End fun _ => 20)
inl e = hash |> sm'.range (am'.Start 20i32) (am'.End fun _ => 32)
$'$"{!a}-{!b}-{!c}-{!d}-{!e}"' |> new_guid
In [ ]:
//// test
///! fsharp
///! cuda
///! rust
///! typescript
///! python
""
|> hash_guid
|> _assert_eq' (new_guid "00000000-0000-0000-0000-000000000000")
"123456789012345678901234567890123"
|> hash_guid
|> _assert_eq' (new_guid "12345678-9012-3456-7890-123456789012")
.py output (Cuda): __assert_eq' / actual: 00000000-0000-0000-0000-000000000000 / expected: 00000000-0000-0000-0000-000000000000 __assert_eq' / actual: 12345678-9012-3456-7890-123456789012 / expected: 12345678-9012-3456-7890-123456789012 .rs output: __assert_eq' / actual: Guid(00000000-0000-0000-0000-000000000000) / expected: Guid(00000000-0000-0000-0000-000000000000) __assert_eq' / actual: Guid(12345678-9012-3456-7890-123456789012) / expected: Guid(12345678-9012-3456-7890-123456789012) .ts output: __assert_eq' / actual: 00000000-0000-0000-0000-000000000000 / expected: 00000000-0000-0000-0000-000000000000 __assert_eq' / actual: 12345678-9012-3456-7890-123456789012 / expected: 12345678-9012-3456-7890-123456789012 .py output: __assert_eq' / actual: 00000000-0000-0000-0000-000000000000 / expected: 00000000-0000-0000-0000-000000000000 __assert_eq' / actual: 12345678-9012-3456-7890-123456789012 / expected: 12345678-9012-3456-7890-123456789012
.fsx output: __assert_eq' / actual: 00000000-0000-0000-0000-000000000000 / expected: 00000000-0000-0000-0000-000000000000 __assert_eq' / actual: 12345678-9012-3456-7890-123456789012 / expected: 12345678-9012-3456-7890-123456789012
main¶
In [ ]:
inl main () =
$'let new_guid x = !new_guid x' : ()
$'let hash_guid x = !hash_guid x' : ()
$'let new_raw_guid x = !new_raw_guid x' : ()