Been reading Learn You A Haskell For a Great Good ! and have big trouble with understanding instance and kind.
Q1: So the type t
in Tofu t
acts as a function with the kind signature (* -> (* -> *)) -> *
? And the overall kind signature of tofu
is * -> *
, isnt it? since (* -> *) -> *
results in *
and so does (* -> (* -> *)) -> *
Q2: When we want to make Frank a b
instance of the typeclass Tofu t
, data type Frank a b
must also have the same kind with t
. That means kind of a
is *
, b
is * -> *
, and b a
which will be (* -> *) -> *
which results in *
. Is that correct?
Q3: The x
in tofu x
represents j a
since both have the kind of *
. Frank
with its kind (* -> (* -> *)) -> *
is applied on x
. But I'm not sure how presenting j a
as x
will distinguish the x
in tofu x
which is j a
and the x
in Frank x
which is a j
.
I'm kind of new to the idea of having a function inside data type or class (Ex: b
in Frank a b
or t
in Tofu t
) which is a bit confusing
I leave the link here since quoting would make the post look unnecessarily long. link
class Tofu t where
tofu :: j a -> t a j
data Frank a b = Frank {frankField :: b a}
instance Tofu Frank where
tofu x = Frank x
instance Tofu Frank
equation, there's no LHS binding fort
orb
. Where are they coming from? – AntC:kind
that LYAH shows, there's also:info
, that tells you everything GHC knows about your names. For example:i Tofu
tells you inferred kind fort
;:i Frank
tells you inferred kinds fora, b
. – AntCinstance
code was wrong. I have fixed it. – Jungtofu
. (Addderiving Show
to the data decl forFrank
.) Writingtofu (Just "hello")
gives nasty type errors. – AntC