ADTs in Typed Racket with macros
Немного изящного (макроебства)[http://lexi-lambda.github.io/blog/2015/12/21/adts-in-typed-racket-with-macros/] и в тайпед/ракетке можно юзать ADT с паттерн матчингом.
(Прямо как во взрослых крутых языках).
(define-datatype Expr
(Value Number)
(Add Expr Expr)
(Subtract Expr Expr)
(Multiply Expr Expr)
(Divide Expr Expr))
(: evaluate (Expr -> Number))
(define (evaluate e)
(match e
[(Value x) x ]
[(Add a b) (+ (evaluate a) (evaluate b))]
[(Subtract a b) (- (evaluate a) (evaluate b))]
[(Multiply a b) (* (evaluate a) (evaluate b))]
[(Divide a b) (/ (evaluate a) (evaluate b))]))
> (evaluate (Add (Value 1)
(Multiply (Divide (Value 1) (Value 2))
(Value 7))))
4 1/2
Интересно, ебанется ли кто-нить достаточно чтобы набыдлить какой-нить аналог хаскеля или scalaz?
the Strict language extension*
Add a new language extension -XStrict
which turns all bindings strict
as if the programmer had written a !
before it. This also upgrades
ordinary Haskell to allow recursive and polymorphic strict bindings.
https://github.com/ghc/ghc/commit/46a03fbec6a02761db079d1746532565f34c340f
Все теперь можно думать о том, чтобы учить хаскель. // Ну или Ocaml
Кстати, спалите haskell vs ocaml в вопросах:
* C-FFI
* многопоточности
* ease of deployment
* поддержки ARM
* легкости получения soft realtime
Олсо, кто-нить объекты в Ocaml юзает или это шутка?
Наткнулся на такой комент на HN:
/However, with a few minor tweaks (e.g. an option type), I would rather have the C# type inference than the OCaml one. The reason is that, if I want to do something very clever, I will not find myself limited to code that I can actually prove to the OCaml compiler as correct: I have, time and time again, resorted to reflection and code generation to work around such situations. In other words C#'s Obj.magic is a lot more powerful (and safe, and expressive) than OCaml's.
A fairly good example is Eliom's way of expressing the parameters of a service. In C# you would write in a PageController class
public Details Update(PageId id, UserId user, [PostBody] Details body)
and have your web framework automatically bind this to POST /page/update/{id}?user={user} with the appropriate serialization for PageId and UserId. And writing such a framework is easy: a couple hundred lines of code, with run-time type safety.
In OCaml you have to understand the entire Eliom_parameter framework: https://ocsigen.org/eliom/4.2/api/server/Eliom_parameter Just think of the mental firepower needed to create that framework in the first place!/