How can I use a type synonym in an instance declaration?

Tom Ellis

I'd like to make synonyms for a class constraint like the following (very much simplified) example

{-# LANGUAGE ConstraintKinds #-}

type Foo = Functor

data MyFunctor a = MyFunctor

instance Foo MyFunctor where
  fmap _ _ = MyFunctor

but I get fmap is not a (visible) method of class Foo.

It seems like I should be able to do this because the GHC documentation says "... standard constraints, tuples and type synonyms for those two sorts of constraint are permitted in instance contexts and superclasses". I'm on GHC 7.6.

GS - Apologise to Monica

Your case isn't covered by those statements in the GHC documentation. An instance context using Foo is something like:

 instance Foo a => Bar a

A superclass would be something like:

 class Foo a => Bar a

i.e. you're defining some other class or instance and Foo/Functor is one of the requirements. Here you're actually trying to define Functor itself and you have to use the real class name.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

How can I copy a templated instance with a virtual base class?

来自分类Dev

How can I use the constraints in native webrtc?

来自分类Dev

How can I save a <template> for a second use?

来自分类Dev

SWIFT: How I can use subscriberCellularProviderDidUpdateNotifier with Swift

来自分类Dev

what object type/instance to use for synchronization

来自分类Dev

How can I recursively find the *directories* containing a file of a certain type?

来自分类Dev

In Puppet, how can I access a variable/attribute inside a defined type?

来自分类Dev

How can I use Laravel form model binding with bootstrap?

来自分类Dev

How can I use a ternary operator for Graphql frontmatter?

来自分类Dev

How can I use urllib.request.urlretrieve with python 2.7

来自分类Dev

How can I use google web fonts with phantomjs

来自分类Dev

How can I use oh-my-zsh with PHPStorm?

来自分类Dev

How can I use jQuery to move multiple instances of a div?

来自分类Dev

How can I use find() on a map inside a vector of maps?

来自分类Dev

how can i use setInterval to run it frequently in as 2.0

来自分类Dev

How can I use the multidimensional index returned by max or min?

来自分类Dev

Windows: How can I use the command line to set registry permissions

来自分类Dev

Windows: How can I use the command line to set registry permissions

来自分类Dev

Generic type in class declaration

来自分类Dev

How to get the parameterized type of an instance with Dart and smoke?

来自分类Dev

Isabelle定义中的type_synonym vs consts

来自分类Dev

Isabelle定义中的type_synonym vs consts

来自分类Dev

How can I show entered password using tooltip on input type=password in bootstrap?

来自分类Dev

Do I need to set type face-manually to roboto-light if i am targeting api 11+ or can I just use android:fontFamily="sans-serif-light"

来自分类Dev

Can I pass a Class type as a procedure parameter

来自分类Dev

how can I convert this to use Rx rather than .NET style events?

来自分类Dev

How can I use git revert to restore all mistakenly deleted files?

来自分类Dev

How can I use SQL's YEAR(), MONTH() and DAY() in Doctrine2?

来自分类Dev

How can I define an UUID for a class, and use __uuidof, in the same way for g++ and Visual C++?

Related 相关文章

  1. 1

    How can I copy a templated instance with a virtual base class?

  2. 2

    How can I use the constraints in native webrtc?

  3. 3

    How can I save a <template> for a second use?

  4. 4

    SWIFT: How I can use subscriberCellularProviderDidUpdateNotifier with Swift

  5. 5

    what object type/instance to use for synchronization

  6. 6

    How can I recursively find the *directories* containing a file of a certain type?

  7. 7

    In Puppet, how can I access a variable/attribute inside a defined type?

  8. 8

    How can I use Laravel form model binding with bootstrap?

  9. 9

    How can I use a ternary operator for Graphql frontmatter?

  10. 10

    How can I use urllib.request.urlretrieve with python 2.7

  11. 11

    How can I use google web fonts with phantomjs

  12. 12

    How can I use oh-my-zsh with PHPStorm?

  13. 13

    How can I use jQuery to move multiple instances of a div?

  14. 14

    How can I use find() on a map inside a vector of maps?

  15. 15

    how can i use setInterval to run it frequently in as 2.0

  16. 16

    How can I use the multidimensional index returned by max or min?

  17. 17

    Windows: How can I use the command line to set registry permissions

  18. 18

    Windows: How can I use the command line to set registry permissions

  19. 19

    Generic type in class declaration

  20. 20

    How to get the parameterized type of an instance with Dart and smoke?

  21. 21

    Isabelle定义中的type_synonym vs consts

  22. 22

    Isabelle定义中的type_synonym vs consts

  23. 23

    How can I show entered password using tooltip on input type=password in bootstrap?

  24. 24

    Do I need to set type face-manually to roboto-light if i am targeting api 11+ or can I just use android:fontFamily="sans-serif-light"

  25. 25

    Can I pass a Class type as a procedure parameter

  26. 26

    how can I convert this to use Rx rather than .NET style events?

  27. 27

    How can I use git revert to restore all mistakenly deleted files?

  28. 28

    How can I use SQL's YEAR(), MONTH() and DAY() in Doctrine2?

  29. 29

    How can I define an UUID for a class, and use __uuidof, in the same way for g++ and Visual C++?

热门标签

归档