Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/Data/Symbol.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ module Data.Symbol
, SProxy(..)
) where

import Type.Proxy (Proxy(..))

-- | A value-level proxy for a type-level symbol.
data SProxy (sym :: Symbol) = SProxy

-- | A class for known symbols
class IsSymbol (sym :: Symbol) where
reflectSymbol :: SProxy sym -> String
reflectSymbol :: Proxy sym -> String

-- local definition for use in `reifySymbol`
foreign import unsafeCoerce :: forall a b. a -> b

reifySymbol :: forall r. String -> (forall sym. IsSymbol sym => SProxy sym -> r) -> r
reifySymbol s f = coerce f { reflectSymbol: \_ -> s } SProxy where
reifySymbol :: forall r. String -> (forall sym. IsSymbol sym => Proxy sym -> r) -> r
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should use a type variable proxy instead of Proxy, for the same reason as reflectProxy - that is, so that it works with both Proxy and SProxy until we update it again later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I've fixed that in latest commits.

reifySymbol s f = coerce f { reflectSymbol: \_ -> s } Proxy where
coerce
:: (forall sym1. IsSymbol sym1 => SProxy sym1 -> r)
-> { reflectSymbol :: SProxy "" -> String } -> SProxy "" -> r
:: (forall sym1. IsSymbol sym1 => Proxy sym1 -> r)
-> { reflectSymbol :: Proxy "" -> String } -> Proxy "" -> r
coerce = unsafeCoerce

16 changes: 15 additions & 1 deletion src/Type/Proxy.purs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,21 @@
-- | ```
module Type.Proxy where

import Prelude
import Control.Applicative (class Applicative)
import Control.Apply (class Apply)
import Control.Bind (class Bind, class Discard)
import Control.Monad (class Monad)

import Data.BooleanAlgebra (class BooleanAlgebra)
import Data.Bounded (class Bounded)
import Data.CommutativeRing (class CommutativeRing)
import Data.Eq (class Eq)
import Data.Functor (class Functor)
import Data.HeytingAlgebra (class HeytingAlgebra)
import Data.Ord (class Ord)
import Data.Ring (class Ring)
import Data.Semiring (class Semiring)
import Data.Show (class Show, show)

-- | Proxy type for all `kind`s.
data Proxy :: forall k. k -> Type
Expand Down