I'm trying to recover the Symbol
used in the type of a value:
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Temp where
import GHC.TypeLits
data Temp (d :: Symbol) (a :: *) where
T :: a -> Temp d a
{-
description :: SingI Symbol d => Temp d a -> Sing Symbol d
-}
description (_ :: Temp d a) = (sing :: Sing d)
This loads fine in ghci
(version 7.6.1):
% ghci
GHCi, version 7.6.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :l Temp
[1 of 1] Compiling Temp ( Temp.hs, interpreted )
Ok, modules loaded: Temp.
*Temp> :t description
description :: SingI Symbol d => Temp d a -> Sing Symbol d
However, if I try to use the type inferred by ghci
in the module itself (uncommenting the line in Temp.hs), I get the following error:
Temp.hs:14:16:
`SingI' is applied to too many type arguments
In the type signature for `description':
description :: SingI Symbol d => Temp d a -> Sing Symbol d
Which makes sense to me, since Sing
and SingI
seem to take a single parameter in the documentation.
What's the proper type signature for description
?
Ok, got it through some monkeying about:
description :: SingI d => Temp d a -> Sing d
Looks like there's some funky rewriting going on, but good enough for now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With