c-enum

To make a type corresponding to an enum of C language

https://github.com/YoshikuniJujo/c-enum#readme

Version on this page:0.1.0.1
LTS Haskell 19.19:0.1.1.3
Stackage Nightly 2022-08-17:0.1.1.3
Latest on Hackage:0.1.1.3

See all snapshots c-enum appears in

BSD-3-Clause licensed by Yoshikuni Jujo
This version can be pinned in stack with:c-enum-0.1.0.1@sha256:d3a9df519b3dc1780378b420c749cb79c4c55bf8d61d61e366f8ce4916f9e7fc,1401

Module documentation for 0.1.0.1

c-enum

foo.h

#ifndef _FOO_H
#define _FOO_H

typedef enum { FOO_ERROR = - 1, FOO_ZERO, FOO_ONE, FOO_TWO, FOO_THREE } Foo;

#endif

Foo.hsc

{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE PatternSynonyms #-}
{-# OPTIONS_GHC -Wall -fno-warn-tabs #-}

module Foo where

import Foreign.C.Enum

#include "foo.h"

enum "Foo" ''#{type Foo} [''Show, ''Read, ''Eq] [
	("FooError", #{const FOO_ERROR}),
	("FooZero", #{const FOO_ZERO}),
	("FooOne", #{const FOO_ONE}),
	("FooTwo", #{const FOO_TWO}),
	("FooThree", #{const FOO_THREE}) ]

You get patterns FooError, …, FooThree. And instance Show Foo and instance Read Foo like the following.

> FooOne
FooOne
> Foo 1
FooOne
> Foo 5
Foo 5
> read "FooTwo" :: Foo
FooTwo
> read "Foo 3" :: Foo
FooThree

Changes

Changelog for c-enum

Unreleased changes