Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't use ghci-inferred type signature for function returning Sing (d :: Symbol)

Tags:

haskell

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?

like image 298
rampion Avatar asked Nov 03 '22 15:11

rampion


1 Answers

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.

like image 198
rampion Avatar answered Nov 15 '22 07:11

rampion