MnZrK
MnZrK

Reputation: 1380

Declare a type with unused type function argument

By 'type function argument' I mean this

> newtype Wrapper f a = Wrapper (f a)
> :kind Wrapper
Wrapper :: (* -> *) -> * -> *

So f here is a type function argument, so I can construct type like this

> :kind Wrapper Maybe Int
Wrapper Maybe Int :: *

Now the problem for me is that I actually use f in the value of Wrapper, and I want to ignore it:

> newtype Wrapper f a = Wrapper a
> :kind Wrapper
Wrapper :: * -> * -> *

Guess what! f is no longer a type function and causes my previous type construction to fail:

> :kind Wrapper Maybe Int
<interactive>:1:9: error:
    • Expecting one more argument to ‘Maybe’
      Expected a type, but ‘Maybe’ has kind ‘* -> *’
    • In the first argument of ‘Wrapper’, namely ‘Maybe’
      In the type ‘Wrapper Maybe Int’

So how can I construct type same way (Wrapper Maybe Int) without the need to have concrete Maybe value inside my Wrapper value?

Upvotes: 3

Views: 66

Answers (1)

MnZrK
MnZrK

Reputation: 1380

Turns out I just need to use language extension:

> {-# LANGUAGE KindSignatures #-}

> newtype Wrapper (f :: * -> *) a = Wrapper a

> :kind Wrapper
Wrapper :: (* -> *) -> * -> *

Upvotes: 7

Related Questions