[Haskell-cafe] sharing

Tom Schouten tom at zwizwa.be
Thu Feb 6 01:07:10 UTC 2020


On 2/5/20 4:29 PM, MarLinn wrote:
>> I've tried something similar before but ran into a lot of cases where 
>> verbose intermediate type annotations where necessary to resolve 
>> double-wrapping ambiguities because the monad is abstract in my case:
>>
>> xor :: DSL m r => r S -> r S -> m (r S)
>
> Do I understand correctly that the actual content of the streams is 
> not important, so S is isomorphic to ()? Or are the contents 
> abstracted away into a more complex type? If it's the former, I fail 
> to see why the monadic interface is even necessary.

Currently S is a fixed type representing the scalar value of the signal 
type. Not very important, but there will be more than one (think float, 
int, complex float, matrix, ...).

The eventual goal is to create a number of primitives that are fairly 
independent of substrate (code for CPU or DSP, Parallel logic, bitserial 
logic, time-sliced programmable datapath, ...), but before all of that 
I'm trying to get the composition mechanism right first, then later 
extend with some base types and encode bit size in types etc.

This is mostly from the Tagless-Final papers and examples.  I like that 
approach and it makes it straightforward for me to change the language 
later.


>
> More broadly, could you provide a bigger example of what you're going 
> for? I have a rough idea of what the goal is, but a more specific 
> example might help.
>
I can point to the code. This needs a lot of work, but here is the main 
class:

https://github.com/zwizwa/asm_tools/blob/master/asm-tools-seq/Language/Seq.hs

You can interpret a program written in Seq as a stateful sequential 
logic circuit where the m hides all the registers, or as an operator on 
streams.


And here are two instances: compiler and interpreter:

https://github.com/zwizwa/asm_tools/blob/master/asm-tools-seq/Language/Seq/Term.hs

https://github.com/zwizwa/asm_tools/blob/master/asm-tools-seq/Language/Seq/Emu.hs

Logic library:

https://github.com/zwizwa/asm_tools/blob/master/asm-tools-seq/Language/Seq/Lib.hs

A circuit for a small CPU:

https://github.com/zwizwa/asm_tools/blob/master/asm-tools-seq/Language/Seq/CPU.hs


> I also feel like there might be a way to adapt Sebastiaan's idea 
> still. But if there isn't yet, there is also a pry-bar lying around: 
> RebindableSyntax. All of pure, return, (<*>), fmap, and (>>=) can be 
> overwritten, and will be used in (applicative) do notation.

Thanks I was unaware of that.




More information about the Haskell-Cafe mailing list