<div dir="ltr"><div><div>Yep. Well, tuples of one element aren't great, but a function Int -> a is a reasonable interface for an array type. But you won't get the nice bracket syntax you want.<br><br></div>More generally, though, the problem is that this type is more general, so you can't make any assumptions about it. A function Int -> a can do whatever, not just look things up in an array. Depending on what you need, this could be fine, but how would you write a function for length?<br><br></div>Thinking about it a bit more, it's really not the best approach for most cases, but it's the only way I can think of for making bracket syntax (or something like it) work.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 1, 2015 at 1:29 PM, KC <span dir="ltr"><<a href="mailto:kc1956@gmail.com" target="_blank">kc1956@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><p dir="ltr">Then a tuple might work better as input to a function to index into an array</p>
<p dir="ltr">e.g. myArray  (5)</p>
</span><p dir="ltr">--<br>
--</p><span class="im HOEnZb">
<p dir="ltr">Sent from an expensive device which will be obsolete in a few months! :D</p>
<p dir="ltr">Casey<br>
    </p>
</span><div class="HOEnZb"><div class="h5"><div class="gmail_quote">On Jun 1, 2015 1:21 PM, "Tikhon Jelvis" <<a href="mailto:tikhon@jelv.is" target="_blank">tikhon@jelv.is</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>You could make myArray a function that takes a list as an input. Of course, all your other array functions have to account for this too. A potential advantage is that this approach leaves the underlying array type abstract, so you could mix and match different data structure on the backend. (IntMap, Array, Vector… etc.) <br><br>A disadvantage is that this is non-standard usage which could be confusing to people and there's no way I know of to statically ensure the list passed in always had one element. That is, myArray [1, 2] would be legal and result in a runtime error.<br></div><div><br></div>I don't know of a way to do it while using a normal array type directly.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 1, 2015 at 1:17 PM, KC <span dir="ltr"><<a href="mailto:kc1956@gmail.com" target="_blank">kc1956@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">I think someone had a complicated program to use brackets for array indexing - is it possible to use a DSL for this?</p>
<p dir="ltr">That is, to use myArray [5] and have a DSL convert it to standard Haskell syntax</p>
<p dir="ltr">--<br>
--</p>
<p dir="ltr">Sent from an expensive device which will be obsolete in a few months! :D</p>
<p dir="ltr">Casey<br>
    </p>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>
</blockquote></div>
</div></div></blockquote></div><br></div>