There are lots of representations for strings. In most languages they pick one set of tradeoffs and run with it. In haskell the "default" implementation (at least the one in the prelude) is a pretty bad choice, but unlike most other languages (really) good implementations exist for pretty much every way you can twist these things. This can be a good thing, but it also leads to confusion, and frustration to find the right types and how to convert them.
initialCommands in console := { | |
""" | |
scala.tools.nsc.interpreter.replProps.power.enable | |
scala.concurrent.ops.spawn{ | |
Thread.sleep(5000) | |
scala.tools.nsc.interpreter.replProps.power.disable | |
print("\nreset\nscala> ") | |
} | |
""" | |
} |
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.example</groupId> | |
<artifactId>my-project</artifactId> | |
<version>0.0.1-SNAPSHOT</version> | |
<dependencies> | |
<!-- none yet --> |
// Note this requires scalaz-core 7.0 added to the classpath. | |
import scalaz._ | |
import Scalaz._ | |
import Lens._ | |
case class Address(street: String, country: String) | |
case class User(name: String, address: Address) | |
val address = Address("Monkey Street", "England") | |
val user = User("Sean", address) |
One of the best ways to reduce complexity (read: stress) in web development is to minimize the differences between your development and production environments. After being frustrated by attempts to unify the approach to SSL on my local machine and in production, I searched for a workflow that would make the protocol invisible to me between all environments.
Most workflows make the following compromises:
-
Use HTTPS in production but HTTP locally. This is annoying because it makes the environments inconsistent, and the protocol choices leak up into the stack. For example, your web application needs to understand the underlying protocol when using the
secure
flag for cookies. If you don't get this right, your HTTP development server won't be able to read the cookies it writes, or worse, your HTTPS production server could pass sensitive cookies over an insecure connection. -
Use production SSL certificates locally. This is annoying
import scalaz._,Scalaz._,scalaz.effect._,OptionT._,Kleisli._ | |
type OptionTIO[+X] = OptionT[IO, X] | |
val reader1: ReaderT[Option, Int, String] = kleisli[Option, Int, String](n => n.toString.some) | |
val reader2: ReaderT[IO, Int, String] = kleisli[IO, Int, String](n => IO((n * 2).toString)) | |
val convertedReader1: ReaderT[OptionTIO, Int, String] = reader1.mapK[OptionTIO, String](opt => optionT(IO(opt))) | |
val convertedReader2: ReaderT[OptionTIO, Int, String] = reader2.mapK[OptionTIO, String](io => io.liftM[OptionT]) |
sealed trait Interact[A] | |
case class Ask(prompt: String) | |
extends Interact[String] | |
case class Tell(msg: String) | |
extends Interact[Unit] | |
trait Monad[M[_]] { | |
def pure[A](a: A): M[A] |
import java.io.File | |
import scala.io.Source | |
object MarkovChainApp extends App { | |
val tokenisedText = Source.fromFile(new File(args(0))).mkString.split(" ").map(_.trim) | |
val wordMap : Map[String, List[String]] = tokenisedText.sliding(2).foldLeft(Map[String, List[String]]().withDefaultValue(List.empty[String])) { | |
(dict, words) => { | |
dict.updated(words(0), words(1) :: dict(words(0)) ) |