オーバーロードに関するメモ
#malgo
Malgoに多相レコードとオーバーロードを追加したい。
構想
(+) : Num a => a -> a -> aをやりたい
Num aはユーザ定義できてほしい
型推論できてほしい
ロードマップ
トップレベル変数✅
f : T = x
レコード構文に;ターミネータを追加✅
Eqを追加 Eqクラス
class, implを追加
Row typeを追加
code:Show.mlg
module Show = {
class Show a = {
show : a -> String;
};
impl showInt32 : Show Int32 = {
show = { x -> int32ToString x };
};
print : Show a => a -> ();
print = { x -> putStr (show x) };
}
code:Num.mlg
module Num = {
class Num a = {
add : a -> a -> a;
};
impl addInt32 : Num Int32 = {
add = { x y -> addInt32 x y };
};
(+) = add;
}
Purescriptのpurescript-recordライブラリ https://github.com/purescript/purescript-record
Objects and Aspects: Row Polymorphism https://www.cs.cmu.edu/~aldrich/courses/819/slides/rows.pdf
Ordo is a minimal statically-typed functional programming language with a ml-like syntax and focused around row polymorphism. https://github.com/FrankBro/ordo
SML#の拡張機能:レコード多相性 https://smlsharp.github.io/ja/documents/4.0.0/Ch8.html
A Polymorphic Type System for Extensible Records and Variants
A Polymorphic Record Calculus and Its Compilation
Haskellのextensibleライブラリ https://www.schoolofhaskell.com/user/fumieval/extensible/extensible-records
Scala2のimplicit parameters https://docs.scala-lang.org/tour/implicit-parameters.html
Scala3のgiven https://docs.scala-lang.org/scala3/reference/contextual.html
An Introduction to Givens in Scala 3 https://blog.knoldus.com/an-introduction-to-givens-in-scala-3/
Typing Haskell in Haskell https://web.cecs.pdx.edu/~mpj/thih/
F#のレコード https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/records
フィールド名がコンフリクトした時に、プレフィックスを要求する
Swiftのプロトコル https://docs.swift.org/swift-book/LanguageGuide/Protocols.html
Juliaのmethod https://docs.julialang.org/en/v1/manual/methods/
OCamlのModular implicits
How to make ad-hoc polymorphism less ad hoc
A system of constructor classes: overloading and implicit higher-order polymorphism
https://coordination.hatenablog.com/entry/2019/12/24/012049