<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>If everything you use will have a color, position, and velocity
I'd just use a product type, i.e.<br>
<br>
data itemState = ItemState Color Point Vector<br>
<br>
or even <br>
<br>
data ItemState = ItemState (Maybe Color) (Maybe Point) (Maybe
Vector)<br>
<br>
Alternately, if you do want to go the dynamic route,
`Data.Dynamic` in `base` actually has some facilities for dynamic
programming<br>
</p>
<br>
<div class="moz-cite-prefix">On 07/28/2018 05:04 PM, Dennis Raddle
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAKxLvoorcw8WQZ87JxN6kNijqNaHZJbvvE=J7fpKMttP7OFq5A@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<div dir="ltr">
<div>I'm actually working in Purescript, but the issue is pretty
much the same as one would encounter in Haskell.</div>
<div><br>
</div>
<div>My application (animation of math-related ideas) is
changing constantly. It's research, and I don't know where
I'll be with it next week, or even tomorrow.</div>
<div><br>
</div>
<div>For instance, the kinds of "objects" I'm animating
(numbers, equations) and the way they move and interact with
each other is a research project, and I'm constantly ripping
out parts of my application and scavenging them for variations
on a theme.</div>
<div><br>
</div>
<div>My objects need state. At this point I'm thinking of just
putting the state into a map with strings as keys and some
kind of sum type to represent each data item I might need.</div>
<div><br>
</div>
<div>So if I want to represent that an object has a particular
color and position and velocity, <br>
</div>
<div><span style="font-family:monospace,monospace"><br>
</span></div>
<div><span style="font-family:monospace,monospace">itemState =
M.fromList <br>
</span></div>
<div><span style="font-family:monospace,monospace"> [("color"
, DataColor blue )</span></div>
<div><span style="font-family:monospace,monospace">
,("position", DataPoint 500.0 100.0)</span></div>
<div><span style="font-family:monospace,monospace">
,("velocity", DataVector 50.0 45.0 ) ]</span></div>
<div><span style="font-family:monospace,monospace"><br>
</span></div>
<div><span style="font-family:arial,helvetica,sans-serif">Which
starts to look more like a dynamically-typed scripting
language. But it's not hard to work with. I can uses
lenses/prisms to inspect and update state, and it's okay if
my program crashes on encountering malformed state.</span></div>
<div><span style="font-family:arial,helvetica,sans-serif"><br>
</span></div>
<div><span style="font-family:arial,helvetica,sans-serif">What
this lets me do is create new objects that mix and match
parts of old objects, and copy and paste a lot of the code.
<br>
</span></div>
<div><span style="font-family:arial,helvetica,sans-serif"><br>
</span></div>
<div><span style="font-family:arial,helvetica,sans-serif">Is
there a better way to do this? Is there a compromise I can
make that will allow the compiler to help me out more with
finding errors at compile time?</span></div>
<div><span style="font-family:arial,helvetica,sans-serif"><br>
</span></div>
<div><span style="font-family:arial,helvetica,sans-serif">D<br>
</span></div>
<div><span style="font-family:arial,helvetica,sans-serif"><br>
</span></div>
<div><span style="font-family:monospace,monospace"><br>
</span></div>
<div><span style="font-family:monospace,monospace"><br>
</span></div>
<div><br>
</div>
<div><br>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
<a class="moz-txt-link-freetext" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a>
Only members subscribed via the mailman list are allowed to post.</pre>
</blockquote>
</body>
</html>