Henning Sato von Rosen <
henning....@gmail.com> writes:
> Sorry if I'm wrong here, but I'm not sure we are talking about the same
> data-type; I'm not referring to the Rich's examples with Maybe, but his
> examples with records/maps, where some fields may or may not be present.
Right, and in most other type systems, the only way to indicate
field presence is with a Maybe type:
data MyData = MyData
{ oneField = Maybe Int
, twoField = Maybe String
}
So to convey that these fields don't exist, we have to explicitly say
"Nothing":
instance Monoid MyData where
mempty = MyData { oneField = Nothing, twoField = Nothing }
which, in GHC, is known and enforced at compile-time. In lisp, if a
field isn't present in a record, you get nil:
(get {:a 1} :b) ;;=> nil
but this is only decidable at runtime. So core.spec takes this "tooling"
around typechecking and exposes it to the user so they could do program
analysis (like seeing what functions are applicable, etc) at
runtime. Racket's contract system does the same, afaik.
Presumably you could implement a Hindley-Milner type system using
core.spec. That would be cool. E.g. Shen is a lisp with a type system in
which you could implement HM in just a few pages of code.
Not sure if this is helpful, hope you get something out of it.