Here's an ADT which is not a GADT, in Haskell:
data Expr = IntExpr Int | BoolExpr Bool| object FunctorComposition extends App { | |
| trait Functor[F[_]] { | |
| def map[A, B](fa: F[A])(f: A => B): F[B] | |
| } | |
| sealed trait Maybe[+T] | |
| case class Some[T](value: T) extends Maybe[T] | |
| case object None extends Maybe[Nothing] | |
| object Maybe { |
| /// Original C++ implementation found at http://www.wilmott.com/messageview.cfm?catid=10&threadid=38771 | |
| /// C# implementation found at http://weblogs.asp.net/esanchez/archive/2010/07/29/a-quick-and-dirty-implementation-of-excel-norminv-function-in-c.aspx | |
| /* | |
| * Compute the quantile function for the normal distribution. | |
| * | |
| * For small to moderate probabilities, algorithm referenced | |
| * below is used to obtain an initial approximation which is | |
| * polished with a final Newton step. | |
| * | |
| * For very large arguments, an algorithm of Wichura is used. |
| object Main { | |
| trait Language { | |
| type F[X] | |
| def num(i: Int): F[Int] | |
| def add(l: F[Int], r: F[Int]): F[Int] | |
| } |
| object Main { | |
| trait Language { self: Literal => | |
| import self._ | |
| def add(l: F[Int], r: F[Int]): F[Int] | |
| } | |
| trait Literal { |
An interesting choice, probably too late. Right now Scala should focus on reducing paper cuts and puzzlers. This said; if indentation syntax is comming, I want it to be an improvement rather than
extend optionality of braces
we already do it! This is already legal for single-line method definitions
Monocle, like many other Scala FP libraries, was inspired by Haskell. In our case, it is the Lens library by Edward Kmett and al.
In Monocle, we experimented with various optics encoding: pair of functions, Van Laarhoven, profunctor (see LensImpl). The JVM and Haskell runtime are hugely different, and an encoding that works well in Haskell can be inefficient in Scala. For example, Haskell relies on zero cost wrapper (newtype) to effectively select typeclass instances, but we don't have an equivalent in Scala/JVM yet (opaque types may help). You can find some of the benchmarks we made for Lenses in 2015 here.
However, something we didn't do very well was to adapt the API to the specificity of Scala. If you look at Monocle 1.x or 2.x, it has the same interface as Haskell's Lens but in much more clunky way. The example
| -----BEGIN PRIVATE KEY----- | |
| MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC10dxEGINZbF0nIoMtM8705Nqm6ZWdb72DqTdFJ+UzQIRIUS59lQkYLvdQp71767vz0dVlPTikHmiv | |
| dYHRc7Fo6JsmSUsGR3th+fU6d1Wt6cwpMTUXj/qODmubDK/ioVDW7wz9OFlSsCBvylOYp9v2+u/VXwACnBXNxCDezjx4RKcqMFT31WTxqU9OM9J86ChMOW4bFA41aLAJ | |
| ozB+02xis7OV175XdQ5vkVXM9ys6ZoRF/K6NXeHiwcZFtMKyphXAxqU7uGY2a16bC3TEG5/km6Jru3Wxy4nKlDyUjWISwH4llWjdSi99r2c1fSCXlMCrW0CHoznn+22l | |
| YCKtYe8JAgMBAAECggEAGOPDJvFCHd43PFG9qlTyylR/2CSWzigLRfhGsClfd24oDaxLVHav+YcIZRqpVkr1flGlyEeittjQ1OAdptoTGbzp7EpRQmlLqyRoHRpT+MxO | |
| Hf91+KVFk+fGdEG+3CPgKKQt34Y0uByTPCpy2i10b7F3Xnq0Sicq1vG33DhYT9A/DRIjYr8Y0AVovq0VDjWqA1FW5OO9p7vky6e+PDMjSHucQ+uaLzVZSc7vWOh0tH5M | |
| 0GVk17YpBiB/iTpw4zBUIcaneQX3eaIfSCDHK0SCD6IRF7kl+uORzvWqiWlGzpdG2B96uyP4hd3WoPcZntM79PKm4dAotdgmalbueFJfpwKBgQDUy0EyA9Fq0aPF4LID | |
| HqDPduIm4hEAZf6sQLd8Fe6ywM4p9KOEVx7YPaFxQHFSgIiWXswildPJl8Cg5cM2EyMU1tdn5xaR4VIDk8e2JEDfhPtaWskpJp2rU2wHvAXOeAES7UFMrkhKVqqVOdbo | |
| IhlLdcYp5KxiJ3mwINSSO94ShwKBgQDavJvF+c8AINfCaMocUX0knXz+xCwdP430GoPQCHa1rUj5bZ3qn3XMwSWa57J4x |