Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Suggestions for way to improve / clean up this code?
      (Erik Tillett)


----------------------------------------------------------------------

Message: 1
Date: Tue, 28 Mar 2017 11:55:36 -0400
From: Erik Tillett <erik.till...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Suggestions for way to improve /
        clean up this code?
Message-ID:
        <CAKZCED==be9gr5cf-cxn70hrjpeptn7np6kgebhlgja6n4q...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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?

Thanks!

On Mon, Mar 27, 2017 at 8:46 PM, Francesco Ariis <fa...@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@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>



-- 
=========================
   Erik Tillett
   614-893-0420
   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-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 105, Issue 12
******************************************

Reply via email to