#!/usr/bin/env bash | |
# | |
# Script that detects if Scala's SBT is installed and if | |
# not then it automatically downloads and installs it at | |
# a specified path. | |
# | |
# Author: Alexandru Nedelcu (https://alexn.org) | |
# | |
set -e |
Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.
A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.
val square : Int => Int = x => x * x
scala> trait Label[T] { val value: Boolean } | |
defined trait Label | |
scala> def mkInstance(s: String, v: Boolean): Label[s.type] = new Label[s.type] { val value = v } | |
mkInstance: (s: String, v: Boolean)Label[s.type] | |
scala> implicit def lTrue = mkInstance("True", true) | |
lTrue: Label[String("True")] | |
scala> implicit def lFalse = mkInstance("False", false) |
Write a program that does what it’s supposed to do | |
Write idiomatic code | |
Debug a program that you wrote | |
Debug a program someone else wrote | |
Debug the interaction between a system you wrote and one you didn’t | |
File a good bug report | |
Modify a program you didn’t write | |
Test a program you wrote | |
Test a program you didn’t write | |
Learn a new programming language |
Every application ever written can be viewed as some sort of transformation on data. Data can come from different sources, such as a network or a file or user input or the Large Hadron Collider. It can come from many sources all at once to be merged and aggregated in interesting ways, and it can be produced into many different output sinks, such as a network or files or graphical user interfaces. You might produce your output all at once, as a big data dump at the end of the world (right before your program shuts down), or you might produce it more incrementally. Every application fits into this model.
The scalaz-stream project is an attempt to make it easy to construct, test and scale programs that fit within this model (which is to say, everything). It does this by providing an abstraction around a "stream" of data, which is really just this notion of some number of data being sequentially pulled out of some unspecified data source. On top of this abstraction, sca
object Demo { | |
// A couple of type classes with type members ... | |
trait Foo[T] { | |
type A | |
} | |
object Foo { | |
implicit val fooIS = new Foo[Int] { type A = String } | |
} |
So what I understand to be your questions:
- What is a coherency problem?
- What does over constained code look like / cause?
- How do you lose your "desired" instance?
A way to step through understanding this problem:
- Oh shit, If I have local type classes, I have to handle crazy wacky cases in my implementation, this will likely have performance and correctness implications (see Coherency.scala)
- What happens if I close over constraint on construction? Oops if I close over it, I end up with OverConstrained code (see OverConstrainedCode.scala) and worse I still have coherency issues, and the ability to lose my intended behavious (LosingAnInstance.scala)
- Oh wow, if I just don't do local type classes, by never define conflicting implicits, and ascribe a single type to each behaviour, everything is simple and just works.