-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1369 from 47deg/master
New Proposal for the Cats Microsite
- Loading branch information
Showing
55 changed files
with
174 additions
and
877 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.technologies { | ||
display: none; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/src/main/tut/const.md → docs/src/main/tut/datatypes/const.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/src/main/tut/either.md → docs/src/main/tut/datatypes/either.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/src/main/tut/freeapplicative.md → ...src/main/tut/datatypes/freeapplicative.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/src/main/tut/freemonad.md → docs/src/main/tut/datatypes/freemonad.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/src/main/tut/kleisli.md → docs/src/main/tut/datatypes/kleisli.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/src/main/tut/oneand.md → docs/src/main/tut/datatypes/oneand.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/src/main/tut/optiont.md → docs/src/main/tut/datatypes/optiont.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/src/main/tut/state.md → docs/src/main/tut/datatypes/state.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/src/main/tut/validated.md → docs/src/main/tut/datatypes/validated.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
--- | ||
layout: default | ||
layout: page | ||
title: "FAQ" | ||
section: "faq" | ||
position: 4 | ||
--- | ||
|
||
# Frequently Asked Questions | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
layout: default | ||
layout: home | ||
title: "Home" | ||
section: "home" | ||
--- | ||
|
3 changes: 2 additions & 1 deletion
3
docs/src/site/resources_for_learners.md → docs/src/main/tut/resources_for_learners.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,14 @@ | ||
# Type classes | ||
--- | ||
layout: docs | ||
title: "Type Classes" | ||
section: "typeclasses" | ||
position: 1 | ||
--- | ||
{% include_relative typeclasses/typeclasses.md %} | ||
|
||
{% for x in site.pages %} | ||
{% if x.section == 'typeclasses' %} | ||
- [{{x.title}}]({{site.baseurl}}{{x.url}}) | ||
{% endif %} | ||
{% endfor %} | ||
|
||
The type class pattern is a ubiquitous pattern in Scala, its function | ||
is to provide a behavior for some type. You think of it as an | ||
"interface" in the Java sense. Here's an example. | ||
|
||
```tut:silent | ||
/** | ||
* A type class to provide textual representation | ||
*/ | ||
trait Show[A] { | ||
def show(f: A): String | ||
} | ||
``` | ||
This class says that a value of type `Show[A]` has a way to turn `A`s | ||
into `String`s. Now we can write a function which is polymorphic on | ||
some `A`, as long as we have some value of `Show[A]`, so that our function | ||
can have a way of producing a `String`: | ||
|
||
```tut:silent | ||
def log[A](a: A)(implicit s: Show[A]) = println(s.show(a)) | ||
``` | ||
|
||
If we now try to call log, without supplying a `Show` instance, we will | ||
get a compilation error: | ||
|
||
```tut:nofail | ||
log("a string") | ||
``` | ||
|
||
It is trivial to supply a `Show` instance for `String`: | ||
|
||
```tut:silent | ||
implicit val stringShow = new Show[String] { | ||
def show(s: String) = s | ||
} | ||
``` | ||
|
||
and now our call to Log succeeds | ||
|
||
```tut:book | ||
log("a string") | ||
``` | ||
|
||
This example demonstrates a powerful property of the type class | ||
pattern. We have been able to provide an implementation of `Show` for | ||
`String`, without needing to change the definition of `java.lang.String` | ||
to extend a new Java-style interface; something we couldn't have done | ||
even if we wanted to, since we don't control the implementation of | ||
`java.lang.String`. We use this pattern to retrofit existing | ||
types with new behaviors. This is usually referred to as "ad-hoc | ||
polymorphism". | ||
|
||
For some types, providing a `Show` instance might depend on having some | ||
implicit `Show` instance of some other type, for instance, we could | ||
implement `Show` for `Option`: | ||
|
||
```tut:silent | ||
implicit def optionShow[A](implicit sa: Show[A]) = new Show[Option[A]] { | ||
def show(oa: Option[A]): String = oa match { | ||
case None => "None" | ||
case Some(a) => "Some("+ sa.show(a) + ")" | ||
} | ||
} | ||
``` | ||
|
||
Now we can call our log function with a `Option[String]` or a | ||
`Option[Option[String]]`: | ||
|
||
```tut:book | ||
log(Option(Option("hello"))) | ||
``` | ||
|
||
Scala has syntax just for this pattern that we use frequently: | ||
|
||
```tut:silent | ||
def log[A: Show](a: A) = println(implicitly[Show[A]].show(a)) | ||
``` | ||
|
||
is the same as | ||
|
||
```tut:silent | ||
def log[A](a: A)(implicit s: Show[A]) = println(s.show(a)) | ||
``` | ||
|
||
That is that declaring the type parameter as `A : Show`, it will add | ||
an implicit parameter to the method signature (with a name we do not know). |
2 changes: 1 addition & 1 deletion
2
docs/src/main/tut/applicative.md → docs/src/main/tut/typeclasses/applicative.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/src/main/tut/apply.md → docs/src/main/tut/typeclasses/apply.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/src/main/tut/contravariant.md → ...src/main/tut/typeclasses/contravariant.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/src/main/tut/foldable.md → docs/src/main/tut/typeclasses/foldable.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/src/main/tut/functor.md → docs/src/main/tut/typeclasses/functor.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/src/main/tut/imports.md → docs/src/main/tut/typeclasses/imports.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
layout: default | ||
layout: docs | ||
title: "Imports" | ||
section: "imports" | ||
--- | ||
|
2 changes: 1 addition & 1 deletion
2
docs/src/main/tut/invariant.md → docs/src/main/tut/typeclasses/invariant.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.