[Haskell-cafe] using Haskell more like scripting language

Vanessa McHale vanessa.mchale at iohk.io
Sun Jul 29 01:14:18 UTC 2018


If everything you use will have a color, position, and velocity I'd just
use a product type, i.e.

data itemState = ItemState Color Point Vector

or even

data ItemState = ItemState (Maybe Color) (Maybe Point) (Maybe Vector)

Alternately, if you do want to go the dynamic route, `Data.Dynamic` in
`base` actually has some facilities for dynamic programming


On 07/28/2018 05:04 PM, Dennis Raddle wrote:
> I'm actually working in Purescript, but the issue is pretty much the
> same as one would encounter in Haskell.
>
> 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.
>
> 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.
>
> 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.
>
> So if I want to represent that an object has a particular color and
> position and velocity,
>
> itemState = M.fromList
>   [("color"   , DataColor  blue       )
>   ,("position", DataPoint  500.0 100.0)
>   ,("velocity", DataVector 50.0 45.0  ) ]
>
> 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.
>
> 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.
>
> 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?
>
> D
>
>
>
>
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180728/23c31816/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180728/23c31816/attachment.sig>


More information about the Haskell-Cafe mailing list