Source code on Github
{-# OPTIONS --safe #-}
module Prelude.Coercions where

open import Prelude.Init; open SetAsType
open import Prelude.General

infix -1 _↝_
record _↝_ (A : Type ) (B : Type ℓ′) : Typeω where
  field to : A  B
  -- syntax to {A}{B} x = [ A ∋ x ]↝ B
  syntax to {B = B} = to[ B ]
open _↝_ ⦃...⦄ public

private variable
  A : Type 
  B : Type ℓ′
  P : Pred A ℓ″
  Q : Pred A ℓ‴

tos :  A  B   List A  List B
tos .to = map to

instance
  ↝×↜⇒↔ :  A  B    B  A   A  B
  ↝×↜⇒↔ = to , to

private
  𝟚 =   
  pattern 𝕃 = inj₁ tt; pattern  = inj₂ tt

  instance
    ↝Bool : 𝟚  Bool
    ↝Bool .to = λ where
      𝕃  true
        false

    Bool↝ : Bool  𝟚
    Bool↝ .to = λ where
      true   𝕃
      false  

  _ : Bool
  _ = to 𝕃

  _ : 𝟚
  _ = to true

  _ : Bool  Bool
  _ = not  to[ Bool ]  to[ 𝟚 ]

  _ : 𝟚  Bool
  _ = it

infix -1 _⁇_↝_
record _⁇_↝_ (A : Type ) (P : Pred A ℓ′) (B : Type ℓ′) : Typeω where
  field toBecause : (x : A) .{_ : P x}  B
  ⌞_⌟ = toBecause
  syntax toBecause x {p} =  x  p 
open _⁇_↝_ ⦃...⦄ public