From 88b07988eb75c7bd3306a5027dcd7c3523e5d6d7 Mon Sep 17 00:00:00 2001 From: Anupam Jain Date: Wed, 6 Jan 2021 21:42:20 +0530 Subject: [PATCH] Minor fix --- spago.dhall | 2 +- src/Typeable.purs | 9 ++++++--- test/Main.purs | 3 +++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/spago.dhall b/spago.dhall index 9a2c076..1c86410 100644 --- a/spago.dhall +++ b/spago.dhall @@ -3,7 +3,7 @@ Welcome to a Spago project! You can edit this file as you like. -} { name = "typeable" -, dependencies = [ "console", "effect", "psci-support" ] +, dependencies = [ "console", "effect", "psci-support", "either", "arrays" ] , packages = ./packages.dhall , sources = [ "src/**/*.purs", "test/**/*.purs" ] } diff --git a/src/Typeable.purs b/src/Typeable.purs index 3ed2514..4f93d77 100644 --- a/src/Typeable.purs +++ b/src/Typeable.purs @@ -1,9 +1,10 @@ module Typeable where +import Data.Either (Either) import Data.Unit (Unit) import Effect (Effect) --- Indexed Typereps +-- Indexed TypeReps data TypeRep a -- Typeable class @@ -21,8 +22,8 @@ class Tag3 (a :: Type -> Type -> Type) where t3 :: Proxy3 a -- Constructors for the opaque data type foreign import typerepImpl1 :: forall a. Tag1 a => TypeRep a -foreign import typerepImpl2 :: forall a b. Typeable b => Tag2 a => TypeRep (a b) -foreign import typerepImpl3 :: forall a b c. Typeable c => Typeable b => Tag1 c => TypeRep (a b c) +foreign import typerepImpl2 :: forall a b. Tag2 a => Typeable b => TypeRep (a b) +foreign import typerepImpl3 :: forall a b c. Tag3 a => Typeable b => Typeable c => TypeRep (a b c) -- Type equality foreign import eqTypeRep :: forall a b. TypeRep a -> TypeRep b -> Boolean @@ -32,6 +33,8 @@ instance tag1Int :: Tag1 Int where t1 = Proxy1 instance typeableInt :: Typeable Int where typeRep = typerepImpl1 instance tag2Array :: Tag2 Array where t2 = Proxy2 instance typeableArray :: Typeable a => Typeable (Array a) where typeRep = typerepImpl2 +instance tag3Either :: Tag3 Either where t3 = Proxy3 +instance typeableEither :: (Typeable a, Typeable b) => Typeable (Either a b) where typeRep = typerepImpl3 -- DEBUG: Console.log anything foreign import clog :: forall a. a -> Effect Unit diff --git a/test/Main.purs b/test/Main.purs index 5fc8ebd..deb122f 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -2,6 +2,7 @@ module Test.Main where import Prelude +import Data.Either (Either) import Effect (Effect) import Typeable (class Tag1, class Tag2, class Typeable, Proxy1(..), Proxy2(..), TypeRep, clog, eqTypeRep, typeRep, typerepImpl1, typerepImpl2) @@ -11,6 +12,8 @@ main = do clog (eqTypeRep (typeRep :: _ (Array Person2)) typeArrPerson) clog (eqTypeRep (typeRep :: _ (Optional Int)) (typeRepFromVal (Some 1))) clog (eqTypeRep (typeRep :: _ (Optional Person)) (typeRepFromVal (Some 1))) + clog (eqTypeRep (typeRep :: _ (Either Int Person)) (typeRep :: _ (Either Int Person))) + clog (typeRep :: _ (Either (Either Int Int) (Optional (Array (Person))))) where typeArrPerson :: TypeRep (Array Person) typeArrPerson = typeRep