Re:Scala – 1 Star – Would Not Program Again
by yummyfajitas on Monday December 02, 2013 @03:56AM
(#6832575)
A simple example: consider scalaz's NonEmptyList[T] class, which turns a failure to populate a list into a compile error rather than a runtime error.
A more complicated example. In one scala system I worked on we had a master/slave postgres db system. We were replacing a legacy RoR system with a Scala system, and in the RoR system there were all sorts of data inconsistency errors caused by people writing to master and reading from the slaves before replication occurred.
In the Scala system which replaced it, we set up a monadic action system. A function which hit the database would have a type signature either PReader[T] or PWriter[T] - this was the only way to access a java.sql.Connection short of manually calling jdbc. Combining the two forms yields a PWriter:
for {
_ <- putObjectToDB(args)
obj <- getObjectFromDB(args)
yield (render(obj)) // is a PWriter[_]
The whole operation runs in a single transaction against the correct database, and any attempt to do the wrong thing is a compile error.
A more complicated example. In one scala system I worked on we had a master/slave postgres db system. We were replacing a legacy RoR system with a Scala system, and in the RoR system there were all sorts of data inconsistency errors caused by people writing to master and reading from the slaves before replication occurred.
In the Scala system which replaced it, we set up a monadic action system. A function which hit the database would have a type signature either PReader[T] or PWriter[T] - this was the only way to access a java.sql.Connection short of manually calling jdbc. Combining the two forms yields a PWriter:
The whole operation runs in a single transaction against the correct database, and any attempt to do the wrong thing is a compile error.