Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The sense of term ambient in ambient monad

Id documentation states

The identity monad ... is ambient in the sense that plain pure values are values of Id.

What is an ambient? How is the term ambient related to the meaning of pure values? Why can we say pure value of Id, when Id is a type constructor? Then again, is Id actually a type constructor or a proper type because :kind commands gives no output

scala> type Id[A] = A
type Id

scala> :kind -v Id


scala>
like image 843
Mario Galic Avatar asked Jun 20 '20 12:06

Mario Galic


1 Answers

ambient is not a term related to FP or type system, but rather metaphor.

Saying ambient they probably mean that it is wrapping existing type without actually effecting it too much.

val i:Id[Int] = 3
val i2:Int = i       // Id[Int]==Int

Saying plain pure values are values of Id they mean that any value of type X is also a value of Id[X].

val i:Id[Int] = 3:Int
val s:Id[String] = "3":String

You can think of type Id[A] = A as a "function on type level" that returns its parameter A.

Something like this, but on type level:

def Id[T](i:T):T = i

There is no such term as "function on type level", but each type constructor is analogue of function on the type system level.

like image 56
Bogdan Vakulenko Avatar answered Nov 10 '22 03:11

Bogdan Vakulenko