Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispose of Unnecessary OVERLAPPING Pragmas and Deprecated OverlappingInstances Extension #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 6 additions & 10 deletions src/Data/Aeson/TypeScript/Instances.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{-# LANGUAGE QuasiQuotes, OverloadedStrings, TemplateHaskell, RecordWildCards, ScopedTypeVariables, ExistentialQuantification, FlexibleInstances, OverlappingInstances #-}

-- Note: the OverlappingInstances pragma is only here so the overlapping instances in this file
-- will work on older GHCs, like GHC 7.8.4
{-# LANGUAGE QuasiQuotes, OverloadedStrings, TemplateHaskell, RecordWildCards, ScopedTypeVariables, ExistentialQuantification, FlexibleInstances #-}

module Data.Aeson.TypeScript.Instances where

Expand Down Expand Up @@ -42,13 +39,12 @@ instance TypeScript Int where

instance TypeScript Char where
getTypeScriptType _ = "string"
getListTypeScriptType _ = "string"
getListParentTypes _ = []

instance {-# OVERLAPPABLE #-} (TypeScript a) => TypeScript [a] where
getTypeScriptType _ = (getTypeScriptType (Proxy :: Proxy a)) ++ "[]"
getParentTypes _ = (TSType (Proxy :: Proxy a)) : (getParentTypes (Proxy :: Proxy a))

instance {-# OVERLAPPING #-} TypeScript [Char] where
getTypeScriptType _ = "string"
instance (TypeScript a) => TypeScript [a] where
getTypeScriptType _ = getListTypeScriptType (Proxy :: Proxy [a])
getParentTypes _ = getListParentTypes (Proxy :: Proxy [a])

instance (TypeScript a, TypeScript b) => TypeScript (Either a b) where
getTypeScriptType _ = [i|Either<#{getTypeScriptType (Proxy :: Proxy a)}, #{getTypeScriptType (Proxy :: Proxy b)}>|]
Expand Down
13 changes: 13 additions & 0 deletions src/Data/Aeson/TypeScript/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ class (Typeable a) => TypeScript a where
getParentTypes _ = []
-- ^ Get the types that this type depends on. This is useful for generating transitive closures of necessary types.

getListTypeScriptType :: Proxy [a] -> String
getListTypeScriptType _ = (getTypeScriptType (Proxy :: Proxy a)) ++ "[]"
-- ^ Allow the programmer to assign a specialised type to lists. For example,
-- this is used by the predefined TypeScript instance of the Char type,
-- where the type String should have "string" assigned to them, rather than "char[]".

getListParentTypes :: Proxy [a] -> [TSType]
getListParentTypes _ = (TSType (Proxy :: Proxy a)) : (getParentTypes (Proxy :: Proxy a))
-- ^ Allow the programmer to specify parent types specialised to lists. For example,
-- this is used by the predefined TypeScript instance of the Char type,
-- where the type String should have no parent types
-- because TypeScript does not know any type for single characters.

-- | An existential wrapper for any TypeScript instance.
data TSType = forall a. (Typeable a, TypeScript a) => TSType { unTSType :: Proxy a }

Expand Down