How can I promote a function that returns a string with singles?

Using the stack with lts-9.2 (and singletons-2.1), I have this:

   $(singletons [d|
       data EventScans
        = PassThrough
        | SuiteProgress

       -- cn :: EventScans -> [Char]
       cn PassThrough = "all-events"
       cn SuiteProgress = "suite-progress"
    |])

I cannot assign a type signature to this function, and a signature of type inferred - cn :: IsString t => EventScans -> t. AFAIK IsStringdoes not stand out.

Without a type signature on, cnI get a type family cn, as expected. If I try to add a type signature, I get:

* Expected kind `[Char]', but `"all-events"' has kind `Symbol'
* In the type `"all-events"'
  In the type family declaration for `Cn' (haskell-stack-ghc)

What is the right way to do this?

edit If I try to enable a type signature cn :: IsString t => EventScans -> t, I get the following error:

Variable `a_agPb' used as both a kind and a type
 Did you intend to use TypeInType? (haskell-stack-ghc)
Not in scope: type constructor or class `SIsString'
  Perhaps you meant `IsString' (imported from Data.String) (haskell-stack-ghc)
+4
source share
2 answers
0

OverloadedStrings, , :


$(singletons [d|
       data EventScans
        = PassThrough
        | SuiteProgress

       -- cn :: EventScans -> [Char]
       cn PassThrough = ("all-events" :: String)
       cn SuiteProgress = ("suite-progress" :: String)
    |])

, , . Singletons , , , :

{-# LANGUAGE FlexibleInstances   #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications    #-}
{-# LANGUAGE TypeFamilies        #-}

module Main where

import           Data.Proxy
import           GHC.TypeLits

test1 :: String
test1 = getStat $ Proxy @PassTrough

test2 :: String
test2 = getStat $ Proxy @SuiteProgress

data PassTrough
data SuiteProgress

type family Cn d :: Symbol where
  Cn PassTrough = "all-events"
  Cn SuiteProgress = "suite-progress"

getStat :: forall a b . ((Cn a) ~ b, KnownSymbol b) => Proxy a -> String
getStat _ = symbolVal $ Proxy @b

0

Source: https://habr.com/ru/post/1687820/


All Articles