Type classes in Haskell are a language mechanism to support ad hoc polymorphism. They also exist in Scala, Coq, and Isabelle.

learn more…| top users | synonyms (1)

1
vote
2answers
38 views

Why is defining an instance of Choice failing with unknown value?

UPDATE: I'm inlining the code here instead.I'm trying to define an instance of Data.Profunctor.Choice where right is defined by calling left, but for some reason the compiler complains that left is ...
1
vote
3answers
93 views

Aux-like pattern for path dependent types?

Goal: I would like to write feedImplicitInstance[Cat](new CatFood())`and have the same effect as feedExplicitInstance(Cat.CatInstance)(new CatFood())How can I do that ?Is it possible to do ...
0
votes
2answers
56 views

How do I create a typeclass that will account for different container types?

I've been struggling with this issue for an hour or two already, I'm finding it difficult in my mind to translate the mental concept into actual code. It feels like I'm missing some knowledge relating ...
2
votes
2answers
90 views

Is there a way to inform Haskell to unwrap a type class inside a sum type

I will briefly explain my chain of thought before the example so that if any of it does not make sense we are able to fix that as well.Suppose that for each type constructor of my data declaration (...
4
votes
1answer
47 views

How to avoid having to explicitly write composite KnownNat constraints?

I have a typeclass, which imposes a KnownNat constraint:class KnownNat (Card a)=> HasFin a wheretype Card a :: Nat...And, I have instances of this class for several basic "building block"...
2
votes
2answers
56 views

Haskell: function that takes a type argument and returns a value depending on that type?

The question is basically: how do I write a function f in Haskell that takes a value x and a type argument T, and then returns a value y=f x T which depends both on x and T, without explicitly ...
5
votes
1answer
93 views

Can type classes at the type level be simulated with higher-rank types?

I have a pluggable runtime type checker that supports parametric but no ad-hoc polymorphism, because there is no compiling step and type information are erased as soon as the type checker is ...
2
votes
1answer
28 views

Scala Type Classes Understanding Interface Syntax

I'm was reading about cats and I encountered the following code snippet which is about serializing objects to JSON!It starts with a trait like this:trait JsonWriter[A] {def write(value: A): ...
3
votes
1answer
44 views

IsString instance not automatically converted to String

I have a type a which is an instance of the IsString typeclass.If I use something like"foobar" :: aeverything works fine.As soon as I use a function that returns a string, as in("foo" ++ "...
1
vote
3answers
64 views

Haskell: confused about uses of Num typeclass

I'm confused about why this works:f :: Num a=> a -> af x=x * 42But this doesn't:g :: Num a=> a -> ag x=x * 4.2I had understood that Num enclosed all types that implemented ...
5
votes
1answer
58 views

A concise way to factor out multiple typeclasses in Haskell?

In my Haskell codebase, I have many functions that take polymorphic arguments. These polymorphic arguments all need to satisfy the same set of typeclasses (RealFloat a, Floating a, Real a, Show a, Ord ...
1
vote
0answers
42 views

After defining the name of a type classes in Haskell, what does the vertical bar followed by a function mean? [duplicate]

I was taking a look at the megaparsec library and noticed that a class is defined asclass (Stream s, A.Alternative m, MonadPlus m)=> MonadParsec e s m | m -> e s whereI know that I am ...
-3
votes
1answer
31 views

What is the difference between <class 'module'> and <class 'type'> in python?

from tkinter import ttk,filedialog,StringVar,Labelprint (dir())print(type(filedialog))print(type(ttk))print(type(StringVar))print(type(Label))Output :['Label', 'StringVar', '__annotations__', ...
5
votes
3answers
82 views

Avoid tedious implementation of Ord

I have a datatype with quite a few constructors, all of them simple enough that Haskell can derive the Ord instance automatically. As in:data Foo a=A a| B Intderiving (Eq, Ord)Now I want ...
3
votes
2answers
64 views

Haskell generic typeclass with list

I have a class defined like this, so that foo takes a generic type and returns an Integer:class Foo a wherefoo :: a -> Integerand a couple of instances defined so it will work with Bool and ...

153050per page
angop.ao, elkhabar.com, noa.al, afghanpaper.com, bbc.com, time.com, cdc.gov, nih.gov, xnxx.com, github.com,