Skip to content

Instantly share code, notes, and snippets.

@jchia
Last active April 5, 2018 14:39
Show Gist options
  • Select an option

  • Save jchia/8a694a591e985997ba78b4ec7b3dd9ed to your computer and use it in GitHub Desktop.

Select an option

Save jchia/8a694a591e985997ba78b4ec7b3dd9ed to your computer and use it in GitHub Desktop.
ConstraintKinds
{-# LANGUAGE AllowAmbiguousTypes, ConstraintKinds, FlexibleInstances, KindSignatures, RankNTypes, TypeApplications #-}
module Lib3 where
import ClassyPrelude
import Data.Kind (Constraint)
type MyConstraint a = (Show a, Monoid a)
-- The error goes away if I replace 'MyConstraint with Show' on L10,18, but I want to be able to express multiple constraints on L18.
fooF :: forall a. MyConstraint a => a -> String
fooF = const ""
foo :: forall (c :: * -> Constraint) a1 a2 b. (c a1, c a2) => (forall x. c x => x -> b) -> (a1, a2) -> [b]
foo f (x1, x2) = [f x1, f x2]
foo' :: (Int, Bool) -> [String]
-- "The type synonym ‘MyConstraint’ should have 1 argument, but has been given none"
foo' = foo @MyConstraint fooF
{-# LANGUAGE AllowAmbiguousTypes, ConstraintKinds, FlexibleInstances, KindSignatures, RankNTypes, TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-}
module Lib3 where
import ClassyPrelude
import Data.Kind (Constraint)
class MyConstraint a where
fooF :: a -> String
instance (Show a, Enum a) => MyConstraint a where
fooF = const ""
foo :: forall (c :: * -> Constraint) a1 a2 b. (c a1, c a2) => (forall x. c x => x -> b) -> (a1, a2) -> [b]
foo f (x1, x2) = [f x1, f x2]
foo' :: (Int, Bool) -> [String]
foo' = foo @MyConstraint fooF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment