Failed to match polymorphic type in haskell

I'm not sure why k4below does not work when k3it makes it polymorphic enough. The error in ghciis

• Couldn't match type ‘K' a0 a0’ withEnd K'’
  Expected type: K' a0 a0 -> K'' a a
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE GADTs #-}
#!/usr/bin/env stack
-- stack --install-ghc --resolver lts-8.21 runghc --package http-conduit --package lens
{-# LANGUAGE ExistentialQuantification, RankNTypes #-}

module YonedaLan where

type End g = forall a. g a a 

data K'  b c = K'
data K'' b c = K''

k1 :: () -> End K'
k1 x = K'

k2 :: End K' -> End K''
k2 x = case x of (K') -> K''

k3 :: () -> End K''
k3 x = k2 ( k1 x)

k4 :: () -> End K''
k4 = k2 . k1

Besides writing a free point style, is there any good practice for this?

+2
source share
1 answer

The problem is that a GHC type system will never instantiate a type variable for a polymorphic type. This will require consistency in the type system.

In your specific example, we have

(.) :: (b->c) -> (a->b) -> (a->c)

and to check the type k2 . k1, we need to create an instance b ~ End K'that is a polymorphic type.

End K' , . .

newtype End g = End { unEnd :: forall a. g a a }

/ End g . , " " GHC.

, (, Agda, Coq, Idris) ( ), . , Haskell - . , , , .

+4

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


All Articles