Typical use

I am trying to understand the use of literals like haskell. In particular, I thought I would write a function that shows me a type literal for a custom type

newtype Fixed (p :: Nat) a = Fixed a instance (KnownNat p) => Show (Fixed pa) where show _ = show $ natVal (Proxy::Proxy p) 

However ghc (7.8) cannot output KnownNat n0, which means that I am not holding back things as I think it should be. Can anyone suggest what is wrong?

+6
source share
1 answer

You need -XScopedTypeVariables for the GHC to recognize that p your Proxy p matches p your type signature.

 {-# LANGUAGE KindSignatures #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE ScopedTypeVariables #-} import Data.Proxy import GHC.TypeLits newtype Fixed (p :: Nat) a = Fixed a instance (KnownNat p) => Show (Fixed pa) where show _ = show $ natVal (Proxy::Proxy p) 
+7
source

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


All Articles