purescript-typeable/test/Main.purs

60 lines
2.2 KiB
Haskell
Raw Normal View History

2021-01-06 05:04:30 +00:00
module Test.Main where
import Prelude
2021-01-06 16:12:20 +00:00
import Data.Either (Either)
2021-04-22 10:40:00 +00:00
import Data.Typeable (class TagT, TypeRep, eqTypeRep, proxyT, typeRep, typeRepFromVal)
2021-01-06 05:04:30 +00:00
import Effect (Effect)
foreign import clog :: forall a. a -> Effect Unit
2021-01-06 05:04:30 +00:00
main :: Effect Unit
main = do
2021-04-22 10:40:00 +00:00
clog (eqTypeRep (typeRep :: _ Int) (typeRep :: _ Char))
clog (eqTypeRep (typeRep :: _ Int) (typeRep :: _ Int))
clog (typeRep :: _ Char)
clog (typeRep :: _ Int)
clog (typeRep :: _ Array)
2021-01-11 20:04:12 +00:00
clog (typeRep :: _ {name::String, age::Int})
2021-04-22 10:40:00 +00:00
clog (typeRep :: _ (Int -> Either (Either Int Int) (Optional (Array (Person)))))
clog (typeRep :: _ (Either (Either Int Int) (Optional (Array (Person)))))
clog (typeRep :: _ (Either Int Int))
clog (typeRep :: _ (Foo Int Int Int))
clog (eqTypeRep (typeRep :: _ Array) (typeRep :: _ Array))
clog (eqTypeRep (typeRep :: _ Person) typePerson)
2021-01-06 06:16:16 +00:00
clog (eqTypeRep (typeRep :: _ (Array Person)) typeArrPerson)
clog (eqTypeRep (typeRep :: _ (Array Person2)) typeArrPerson)
2021-04-22 10:40:00 +00:00
clog (eqTypeRep typeRecord (typeRep :: _ {name::String, age::Int}))
2021-01-06 06:16:16 +00:00
clog (eqTypeRep (typeRep :: _ (Optional Int)) (typeRepFromVal (Some 1)))
clog (eqTypeRep (typeRep :: _ (Optional Person)) (typeRepFromVal (Some 1)))
2021-01-06 16:12:20 +00:00
clog (eqTypeRep (typeRep :: _ (Either Int Person)) (typeRep :: _ (Either Int Person)))
2021-04-22 10:40:00 +00:00
2021-01-06 06:16:16 +00:00
where
2021-01-11 20:04:12 +00:00
typeRecord :: TypeRep {age::Int, name::String}
typeRecord = typeRep
2021-01-06 06:16:16 +00:00
typeArrPerson :: TypeRep (Array Person)
typeArrPerson = typeRep
typePerson :: TypeRep Person
typePerson = typeRep
2021-01-11 20:04:12 +00:00
-- The following should not compile since Break does not have a typeable instance
-- typeRecordBreak :: TypeRep {break::Break, name::String}
-- typeRecordBreak = typeRep
-- A data type without a typeable instance
data Break
2021-01-06 06:16:16 +00:00
2021-04-22 10:40:00 +00:00
data Foo :: forall k1 k2 k3. k1 -> k2 -> k3 -> Type
data Foo a b c = Foo
2021-04-22 10:40:00 +00:00
instance tagFoo :: TagT Foo where tagT = proxyT
2021-01-06 06:16:16 +00:00
newtype Person = Person { name :: String, location :: String }
2021-04-22 10:40:00 +00:00
instance tagTPerson :: TagT Person where tagT = proxyT
2021-01-06 06:16:16 +00:00
newtype Person2 = Person2 { name :: String, location :: String }
2021-04-22 10:40:00 +00:00
instance tagTPerson2 :: TagT Person2 where tagT = proxyT
2021-01-06 06:16:16 +00:00
data Optional a = None | Some a
2021-04-22 10:40:00 +00:00
instance tagOptional :: TagT Optional where tagT = proxyT