[Haskell-beginners] Suggestions for way to improve / clean up this code?

Erik Tillett erik.tillett at gmail.com
Tue Mar 28 15:55:36 UTC 2017

Ooh, thanks for that!  I didn't even know hlint existed.  That's pretty
cool.  As far as use of the State monad... What I was thinking is that I've
got the CPU state that gets fed into just about every function, which then
returns a new modified CPU.  So I'm constantly passing the CPU around.  I
might want to be able to have hooks that allow me to escape normal updating
of the CPU when something specific happens (maybe an error, maybe something
else).  Would State help with that or are there any better alternatives?


On Mon, Mar 27, 2017 at 8:46 PM, Francesco Ariis <fa-ml at ariis.it> wrote:

> On Mon, Mar 27, 2017 at 07:54:55PM -0400, Erik Tillett wrote:
> > I'm looking for sugestions on how to better structure this code.  I stuck
> > it in a pastbin:
> >
> > https://pastebin.com/gQFmvq6W/
> >
> > Would a State monad help?
> >
> > Thanks!
> Hello Erik,
>     a couple of notes:
> - boolToInt is the same as `fromEnum`
>     λ> :t fromEnum
>     fromEnum :: Enum a => a -> Int
> - there are a lot of redundant brackets, like
>     if (zReg c) then c{pc = address} else c
>        ^      ^
>   minor errors like this are easily caught by hlint
> As for the state monad: you are correctly using monads to capture
> the idea of "things that can fail" (Either), judging by the function
> signatures I don't see the need for a State monad (i.e. I don't
> see signatures that end in (Something, SomeResult).
> (or maybe I am misreading the code, in that case please fire again)
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

   Erik Tillett
   7797 Gladshire Blvd.
   Lewis Center, OH 43035
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20170328/469854c4/attachment.html>

More information about the Beginners mailing list