I think someone had a complicated program to use brackets for array indexing - is it possible to use a DSL for this?

I think someone had a complicated program to use brackets for array indexing - is it possible to use a DSL for this? That is, to use myArray [5] and have a DSL convert it to standard Haskell syntax -- -- Sent from an expensive device which will be obsolete in a few months! :D Casey

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.)
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.
I don't know of a way to do it while using a normal array type directly.
On Mon, Jun 1, 2015 at 1:17 PM, KC
I think someone had a complicated program to use brackets for array indexing - is it possible to use a DSL for this?
That is, to use myArray [5] and have a DSL convert it to standard Haskell syntax
-- --
Sent from an expensive device which will be obsolete in a few months! :D
Casey
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

Then a tuple might work better as input to a function to index into an array
e.g. myArray (5)
--
--
Sent from an expensive device which will be obsolete in a few months! :D
Casey
On Jun 1, 2015 1:21 PM, "Tikhon Jelvis"
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.)
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.
I don't know of a way to do it while using a normal array type directly.
On Mon, Jun 1, 2015 at 1:17 PM, KC
wrote: I think someone had a complicated program to use brackets for array indexing - is it possible to use a DSL for this?
That is, to use myArray [5] and have a DSL convert it to standard Haskell syntax
-- --
Sent from an expensive device which will be obsolete in a few months! :D
Casey
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

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.
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?
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.
On Mon, Jun 1, 2015 at 1:29 PM, KC
Then a tuple might work better as input to a function to index into an array
e.g. myArray (5)
-- --
Sent from an expensive device which will be obsolete in a few months! :D
Casey
On Jun 1, 2015 1:21 PM, "Tikhon Jelvis"
wrote: 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.)
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.
I don't know of a way to do it while using a normal array type directly.
On Mon, Jun 1, 2015 at 1:17 PM, KC
wrote: I think someone had a complicated program to use brackets for array indexing - is it possible to use a DSL for this?
That is, to use myArray [5] and have a DSL convert it to standard Haskell syntax
-- --
Sent from an expensive device which will be obsolete in a few months! :D
Casey
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

On Mon, Jun 1, 2015 at 4:29 PM, KC
Then a tuple might work better as input to a function to index into an array
e.g. myArray (5)
Aside from 1-tuples not being a thing? (That's the same as (myArray 5).) -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

I'm a part time tutor even though I don't look Elizabethan
I was trying to lower the learning curve for students
Maybe I'll point them to
http://dev.stephendiehl.com/hask/
And
Data.Vector
--
--
Sent from an expensive device which will be obsolete in a few months! :D
Casey
On Jun 1, 2015 1:35 PM, "Brandon Allbery"
On Mon, Jun 1, 2015 at 4:29 PM, KC
wrote: Then a tuple might work better as input to a function to index into an array
e.g. myArray (5)
Aside from 1-tuples not being a thing? (That's the same as (myArray 5).)
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

There's some plans to allow more flexible overloaded list syntax that, once
done, would allow list style notation for static sized tuples/lists. But
it's probably not gonna be mature till ghc 7.14 at the current rate.
Hopefully 7.12, but more likely 7.14
On Monday, June 1, 2015, KC
I'm a part time tutor even though I don't look Elizabethan
I was trying to lower the learning curve for students
Maybe I'll point them to http://dev.stephendiehl.com/hask/ And Data.Vector
-- --
Sent from an expensive device which will be obsolete in a few months! :D
Casey
On Jun 1, 2015 1:35 PM, "Brandon Allbery"
javascript:_e(%7B%7D,'cvml','allbery.b@gmail.com');> wrote: On Mon, Jun 1, 2015 at 4:29 PM, KC
javascript:_e(%7B%7D,'cvml','kc1956@gmail.com');> wrote: Then a tuple might work better as input to a function to index into an array
e.g. myArray (5)
Aside from 1-tuples not being a thing? (That's the same as (myArray 5).)
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com javascript:_e(%7B%7D,'cvml','allbery.b@gmail.com'); ballbery@sinenomine.net javascript:_e(%7B%7D,'cvml','ballbery@sinenomine.net'); unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

I'm a part time tutor even though I don't look Elizabethan
I was trying to lower the learning curve for students
Using square brackets for array indexing in Haskell would be more a case of putting a stumbling block in their way than lowering the learning curve. Fortran uses A(I), not A[I], and has for the last fifty-some years. The official definition of Simula 67 uses A(I) as well, despite its predecessor Algol 60 using a[i]. COBOL uses A(I), and has done so nearly as long as Fortran. PL/I (yes, it still exists) uses A(I), not A[I]. BASIC uses A(I), this is still so in Visual Basic.NET. If memory serves me correctly, MINITAB uses parentheses, not brackets. Is a pattern beginning to emerge? Lying to the students by implicitly telling them "all programming languages use square brackets for array indexing" will be doing them no favour. Even lying about Haskell is no kindness.

If you teach them about how operators are normal functions in Haskell,
using an operator to index into an array makes the indexing operation less
magical—a big pedagogical boon, in my view. The fewer special cases in the
language you're teaching, the better, and looking similar to other
languages is not a good reason for a special case.
Especially since the similarity could be misleading!)
On Mon, Jun 1, 2015 at 5:48 PM,
I'm a part time tutor even though I don't look Elizabethan
I was trying to lower the learning curve for students
Using square brackets for array indexing in Haskell would be more a case of putting a stumbling block in their way than lowering the learning curve.
Fortran uses A(I), not A[I], and has for the last fifty-some years. The official definition of Simula 67 uses A(I) as well, despite its predecessor Algol 60 using a[i]. COBOL uses A(I), and has done so nearly as long as Fortran. PL/I (yes, it still exists) uses A(I), not A[I]. BASIC uses A(I), this is still so in Visual Basic.NET. If memory serves me correctly, MINITAB uses parentheses, not brackets.
Is a pattern beginning to emerge?
Lying to the students by implicitly telling them "all programming languages use square brackets for array indexing" will be doing them no favour. Even lying about Haskell is no kindness.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

On Jun 1, 2015 5:52 PM, "Tikhon Jelvis"

Strongly agreed with ok and Tikhon. I've tried these weird pidgins and
localized fabrications wrapped around Haskell before, it's only a stumbling
block.
Haskell is simple, you don't have to lie - just encourage them not to draw
false analogies.
On Mon, Jun 1, 2015 at 7:52 PM, Tikhon Jelvis
If you teach them about how operators are normal functions in Haskell, using an operator to index into an array makes the indexing operation less magical—a big pedagogical boon, in my view. The fewer special cases in the language you're teaching, the better, and looking similar to other languages is not a good reason for a special case.
Especially since the similarity could be misleading!)
On Mon, Jun 1, 2015 at 5:48 PM,
wrote: I'm a part time tutor even though I don't look Elizabethan
I was trying to lower the learning curve for students
Using square brackets for array indexing in Haskell would be more a case of putting a stumbling block in their way than lowering the learning curve.
Fortran uses A(I), not A[I], and has for the last fifty-some years. The official definition of Simula 67 uses A(I) as well, despite its predecessor Algol 60 using a[i]. COBOL uses A(I), and has done so nearly as long as Fortran. PL/I (yes, it still exists) uses A(I), not A[I]. BASIC uses A(I), this is still so in Visual Basic.NET. If memory serves me correctly, MINITAB uses parentheses, not brackets.
Is a pattern beginning to emerge?
Lying to the students by implicitly telling them "all programming languages use square brackets for array indexing" will be doing them no favour. Even lying about Haskell is no kindness.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
participants (6)
-
Brandon Allbery
-
Carter Schonwald
-
Christopher Allen
-
KC
-
ok@cs.otago.ac.nz
-
Tikhon Jelvis