squiggle
squiggle copied to clipboard
Interfaces Brainstorm
- x Is new feature
Description of suggestion or shortcoming:
I think that Interfaces could work a lot like Classes, but with some differences of semantics. Imagine something like,
@name("Values of Squiggle Items")
interface MacrostrategyRelativeValues = {
type = {
fn: [string, string] => [dist, dist],
coveredItems = string[],
confidence: [string, string] => number,
description: string => string
}
validate(e) = List.length(e) > 3
toString(e) = "foobar"
showAs(e) = e.fn
}
....
myRelativeValueEstimate = new MacrostrategyRelativeValues({
fn: {|a,b| [3 to 10, 5 to 20}
)}
myRelativeValueEstimate -> getType // MacrostrategyRelativeValues
myRelativeValueEstimate -> MacrostrategyRelativeValues.toString // presents as string.
....
@name("Distribution")
interface Distribution = {
type = {
pdf: number => number,
inv?: number => number
}
...
}
@name("TimeSeriesForecast")
interface TimeSeriesForecast = {
type = {
fn: date => number,
integral?: date => number
}
...
}
@name("Person")
interface Person = {
type = {
fn: date => number,
integral?: date => number
}
...
}
Maybe we could later simplify somehow.
I love Type Classes with Haskell, but feel safer with leaning more on Modules/Classes. Modules arguably are more scalable/composable (type classes can conflict with each other in weird ways), and probably have an easier learning curve.