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

Francesco Ariis fa-ml at ariis.it
Tue Mar 28 00:46:26 UTC 2017


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)



More information about the Beginners mailing list