Skip to content

Why is Codec a type rather than a type class? #14

@alphashuro

Description

@alphashuro

I have been learning Purescript recently and I have a question if you have some time to entertain me 😅

I was implementing a toy project and before I discovered this package, I created a type class that served as a Codec definition, defining encode and decode functions.

class Codec a b e where
  encode :: a -> b
  decode :: b -> Either e a

I then create an instance of this Codec for each of the types in my domain.

Comparing my implementation to yours, I'm curious about why Codec is implemented as a type in this module rather than a type class?

PS: I know this is probably not the right place for this, let me know if there is a better place to ask such questions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions