6 Dec 2012 01:16

## sequential logic

Hi. I was wondering what the various (and especially most simple)
approaches one could take for working with (simulating or calculating)
sequential logic in Haskell. By sequential logic, I mean like wikipedia
describes, where a system is made up of logic gates, whose output is
dependent not only on the logic operation of the gate, but on the
previous state of the gate. (Like in electronics where the system can be
driven by a clock signal or have memory.)

Does one have to get into FRP for that sort of thing? Or use some kind
of FSM framework? Or is there some kind of fancy state monad suitable
for that? Or...?

I'm no electronic or digital engineer, but for learning purposes I've
been trying to see if I could build an (extremely simple) virtual
processor or calculator in Haskell, using only the Bool type and a few
of the boolean operators (and functions composed of the aforementioned),
reproducing things like half adders and full adders as functions in the
program. Of course, I quickly ran into the stateful aspect of the
problem, in subjects like clock signal and flip flops.

--

--
frigidcode.com

_______________________________________________

6 Dec 2012 01:47

### Re: sequential logic

2012/12/5 Christopher Howard <christopher.howard <at> frigidcode.com>:
> Hi. I was wondering what the various (and especially most simple)
> approaches one could take for working with (simulating or calculating)
> sequential logic in Haskell. By sequential logic, I mean like wikipedia
> describes, where a system is made up of logic gates, whose output is
> dependent not only on the logic operation of the gate, but on the
> previous state of the gate. (Like in electronics where the system can be
> driven by a clock signal or have memory.)
>
> Does one have to get into FRP for that sort of thing? Or use some kind
> of FSM framework? Or is there some kind of fancy state monad suitable
> for that? Or...?
>
> I'm no electronic or digital engineer, but for learning purposes I've
> been trying to see if I could build an (extremely simple) virtual
> processor or calculator in Haskell, using only the Bool type and a few
> of the boolean operators (and functions composed of the aforementioned),
> reproducing things like half adders and full adders as functions in the
> program. Of course, I quickly ran into the stateful aspect of the
> problem, in subjects like clock signal and flip flops.

checking out this programming language:
http://en.wikipedia.org/wiki/Hume_(programming_language)

>
> --
> frigidcode.com
>
>

6 Dec 2012 07:28

### Re: sequential logic

2012-12-06 01:16, Christopher Howard skrev:
> Hi. I was wondering what the various (and especially most simple)
> approaches one could take for working with (simulating or calculating)
> sequential logic in Haskell. By sequential logic, I mean like wikipedia
> describes, where a system is made up of logic gates, whose output is
> dependent not only on the logic operation of the gate, but on the
> previous state of the gate. (Like in electronics where the system can be
> driven by a clock signal or have memory.)
>
> Does one have to get into FRP for that sort of thing? Or use some kind
> of FSM framework? Or is there some kind of fancy state monad suitable
> for that? Or...?
>
> I'm no electronic or digital engineer, but for learning purposes I've
> been trying to see if I could build an (extremely simple) virtual
> processor or calculator in Haskell, using only the Bool type and a few
> of the boolean operators (and functions composed of the aforementioned),
> reproducing things like half adders and full adders as functions in the
> program. Of course, I quickly ran into the stateful aspect of the
> problem, in subjects like clock signal and flip flops.

If you just want to simulate your design, this is actually very easy.
Signals can be represented as a stream of bits (an old idea dating at
least from Sheeran's µFP, 1984):

> type Bit    = Bool
> type Signal = [Bit]

Constant signals are defined using `repeat`: