Created
June 29, 2022 13:37
-
-
Save Savelenko/49b8417c9d85953056f64162bc9c6dd6 to your computer and use it in GitHub Desktop.
Data format selection with static abstract member-based encoder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type IEncodable<'t> = | |
static abstract Encode : 't -> byte[] | |
/// Selects Base64 encoding for `a`. | |
type Base64<'a when 'a :> IEncodable<'a>> = Base64 of 'a with | |
interface IEncodable<Base64<'a>> with | |
member this.Encode (Base64 a) = | |
let toBase64 = failwith "..." | |
toBase64 ('a.Encode a) | |
// Default encoding | |
let bytes = string.Encode "Hello" | |
// Base64 encoding | |
let byte64 = Base64<_>.Encode (Base64 "Hello") // Hypothetical syntax |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment