1
sealed trait Process[+F[_], +O]
/**
 * Created by pach on 11/07/14.
 */
package object stream {

  type Process0[+O] = Process[Nothing,O]
...
}

This is how Process0 defined.

Actually I cannot understand why this compiles, because Nothing takes no type param.

To represent a stream with no effect

why not just set the context type F to value type itself(using identity type constructor, scalaz.Scalaz.Id).

type Process0[+O] = Process[Id, O]
jilen
  • 5,633
  • 3
  • 35
  • 84
  • Why wouldn't you expect it to compile? Being `Nothing` a subtype of all the types the compiler knows that even if you have a complex type, `Nothing` would still be a subtype. – Ende Neu Sep 13 '14 at 07:46
  • @EndeNeu by writing `Process[+F[_], +O]`, we actually expect the `F` has one type parameter, but `Nothing` takes no parameter, so, it is a little surprising – jilen Sep 13 '14 at 07:48
  • I would say that the compiler is smart enough to know that regardless of how a type is constructed or regardless how how many type parameters it takes, `Nothing` will always be a subtype of it, unfortunately there's nothing specific around about this topic. – Ende Neu Sep 13 '14 at 07:59

1 Answers1

1

Scala compiler treats Nothing a bit differently than other types, e.g the same trick won't work with Null, although it's a bottom type for all reference types. You can check subtype relationship using implicits and special method <:<, like this:

scala> implicitly[Nothing <:< List[_]]
res1: <:<[Nothing,List[_]] = <function1>

And if there is no relationship you'll see:

scala> implicitly[Null <:< Int]
<console>:8: error: Cannot prove that Null <:< Int.
              implicitly[Null <:< Int]

As for your main question, i'm not that familiar with scalaz-streams, but as i understand type Id is just a type itself, i.e type Id[A] = A, so if you had Process[Id, O], this would mean that you have some non-effectful input which gives some output. But in case of Process0 there shouldn't be any input at all, it should only generate some output.

4lex1v
  • 21,367
  • 6
  • 52
  • 86