BSD-3-Clause licensed by Yoshikuni Jujo
Maintained by [email protected]
This version can be pinned in stack with:c-enum-0.1.1.3@sha256:ca6a53d5b003051d0d6fb0b69d46b730cacbb03d80166cab7664085306d72aa3,1324

Module documentation for 0.1.1.3

Used by 2 packages in nightly-2024-10-31(full list with versions):

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