1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 17:04:47 +03:00

Use ambiguous types instead of proxies.

This commit is contained in:
Rob Rix 2019-10-03 02:29:36 -04:00
parent 8e9fe4e58a
commit 310e3a36ee
No known key found for this signature in database
GPG Key ID: F188A01508EA1CF7

View File

@ -1,4 +1,4 @@
{-# LANGUAGE DataKinds, FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, OverloadedStrings, ScopedTypeVariables, TypeApplications, TypeFamilies, TypeOperators, UndecidableInstances #-}
{-# LANGUAGE AllowAmbiguousTypes, DataKinds, FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, OverloadedStrings, ScopedTypeVariables, TypeApplications, TypeFamilies, TypeOperators, UndecidableInstances #-}
module Serializing.SExpression.Precise
( serializeSExpression
, ToSExpression(..)
@ -26,7 +26,7 @@ class ToSExpression t where
toSExpression :: t -> Int -> Builder
instance (ToSExpressionBy strategy t, strategy ~ ToSExpressionStrategy t) => ToSExpression t where
toSExpression = toSExpression' @strategy undefined
toSExpression = toSExpression' @strategy
data Strategy = Generic | Show
@ -36,13 +36,13 @@ type family ToSExpressionStrategy t :: Strategy where
ToSExpressionStrategy _ = 'Generic
class ToSExpressionBy (strategy :: Strategy) t where
toSExpression' :: proxy strategy -> t -> Int -> Builder
toSExpression' :: t -> Int -> Builder
instance Show t => ToSExpressionBy 'Show t where
toSExpression' _ t _ = stringUtf8 (show t)
toSExpression' t _ = stringUtf8 (show t)
instance (Generic t, GToSExpression (Rep t)) => ToSExpressionBy 'Generic t where
toSExpression' _ t n = nl n <> pad n <> "(" <> fold (intersperse " " (gtoSExpression (from t) n)) <> ")"
toSExpression' t n = nl n <> pad n <> "(" <> fold (intersperse " " (gtoSExpression (from t) n)) <> ")"
class GToSExpression f where