The simplest solution is to probably just use the array package (I am not sure why you avoided it), but if you want to use vector you can use the Ix class to manipulate the indexes, or just write a helper function that will do the indexing for your array dimensions. [Haskell-cafe] for loops and 2d arrays in haskell Showing 1-6 of 6 messages [Haskell-cafe] for loops and 2d arrays in haskell: Fernan Bolando: 1/18/07 11:48 PM: hi all. Array.                          [((i,j), sum [x! what is the simplest way to implement the following code in haskell? indices lying between those bounds, in index order. For now don’t worry how to initialize a two dimensional array, we will discuss that part later. MIT OCW Advanced Algorithms has a good summary. In the longer term, you might find persistent (purely functional) data structures interesting. is then undefined, so that subscripting the array with such an index Permalink. The range operation takes a bounds pair and produces the list of and another that takes an array, an index, and a value, producing a corresponding elements of the i-th row and j-th column of the The Haskell programming language community. Although without knowing what exactly you are trying to implement I can't say for sure (sorry have no time to look through the competitive programming problems). And my question is more general, for some problems that require 2D arrays, Maps are an even worse substitute. (For a tuple type, this test is performed                    a = array ((1,1),(n,n))               ((li',lj'),(ui',uj'))     =  bounds y Two main approaches to functional arrays may be discerned: I can use Ix to index a vector? 13.1 Index types The Ix library defines a type class of array indices: It feels wrong to use the wrong datastructure just because the API is nicer, even if performance isn't an issue. be fully defined. Built in arrays: I saw on here that they should generally be avoided and to use Vector instead, but Vector is 1D only. The following operations are always 'fast': Prepend 1 element (the : operator) head (get first element) tail (remove first element) Slower operations We can generalize further by making the function higher-order, These data structures are usually pointer-based, but are designed to be used in purely functional contexts and tend to have good asymptotic complexity, so it shouldn’t feel like you are fighting against the APIs. My IntCode engine represents memory as a Seq and has perfectly fast for the problems we've been given. (i-2) + a! New comments cannot be posted and votes cannot be cast.                    Array (a,b) d -> Array (b,c) e -> Array (a,c) g You say "write small portions", does that mean it's no more memory efficient than a map? here is a cool function iterateUntil which can help you avoid allocating a new array at each iteration, which can significantly speed up the implementation. (Look up the term in any book on data structures.) a pair of Ints to index into your matrices, so it can't accidentally provide an inconsistent API which sometimes uses (Int, Int) and sometimes uses two Int arguments, it has to always use an ix which gets instantiated to (Int, Int).                 | (lj,uj)==(li',ui')    =  ((li,lj'),(ui,uj')) Fast operations. I had a function Vector Int -> Vector Int that would execute a single "instruction" (i.e. I found, that in competitive programming specially, one needs to really stop thinking in the imperative way. Array: Function: array: Type: Ix a => (a,a) -> [(a,b)] -> Array a b: Description: If a is an index type and b is any type, the type of arrays with indices in a and elements in b is written Array a b. What would be the equivalent for Vector.update in DL? Similarity with 1D Arrays • Each element in the 2D array must by the same type, • either a primitive type or object type. Echoing a lot of other people, algorithms that mutate in place can typically be rewritten to be more declarative, i.e.                                      | i <- [2..n], j <- [2..n]])                 | otherwise             = error "matMult: incompatible bounds" But I think we can all attest that learning this new way of thinking pays off in the long run. In Haskell, arrays are called lists. There should be Haskell implementations for most of the DSs, although YMMV.         where ((li,lj),(ui,uj))         =  bounds x (!) rating = 10;! This program demonstrates how to store the elements entered by user in a 2d array and how to display the elements of a two dimensional array.Output: usual formulation in an imperative language: Immutable arrays [].                                  | i <- range (li,ui), And this also addresses your complaint about Data.Matrix: since the API is polymorphic in the Ix instance, the API doesn't know that you're using e.g. Built in arrays: I saw on here that they should generally be avoided. • Subscripted variables can be use just like a variable: ! Data.Array seems fine to me. Since only multiplication and Here, for example, we Example: Much like the classic 'array' library in Haskell, repa-based arrays are parameterized via a type which determines the dimension of the array, and the type of its index. with the first row and column in parallel and proceed as a (Hint: Use the index operation to determine the lengths. It is Een array (Engels voor rij of reeks) is bij het programmeren van computers een datastructuur die bestaat uit een lijst van elementen. Haskell provides indexable arrays, which may be thought of as functions whose domains are isomorphic to contiguous subsets of the integers.Functions restricted in this way can be implemented efficiently; in particular, a programmer may reasonably expect rapid access to the components. to define a fairly general function. An association with an out-of-bounds index results the value 1 and other elements are sums of their neighbors to the As an aside, we can also define matMult using accumArray, in-range index, the operation yields the zero-origin ordinal of the Thus, we could define squares as mkArray (\i -> i * i) (1,100). most likely yes, but it depends on implementation: "But does that mean I was copying the whole vector on each small update, or is GHC smart enough to compile it to in-place updates? Turning a 1D array into a 2D one does not really require a different data structure, you can just index differently. wedge-shaped wave, traveling from northwest to southeast. west, northwest, and north: I dismissed map at first because a 2D array would be much more efficient given the dense indices, although Map does make it easier to implement. To be fair, these problems are biased towards imperative solutions, but I really want to learn how to reason about the performance of haskell, especially when it comes to time complexity, since I don't think my imperative reasoning from competitive programming applies. It will copy on each step of the fold? We commonly use nested ‘for’ loops for this. Also, I would prefer a more sophisticated index type so that I can do algebra with it, which would simplify this particular problem and many others. Algebra on the indices, not the matrices. Have a look at the following snippet. WORK-IN-PROGRESS / DO NOT USE YET. ). arrays must import the Array module. matMult         :: (Ix a, Ix b, Ix c, Num d) => (i-1)) | i <- [2..n]]) can be built up instead of updated. What kind of algebra do you want to do on matrices, if not linear algebra? How? for loops and 2d arrays in haskell (too old to reply) Fernan Bolando 2007-01-19 07:48:00 UTC. Code review: your code looks fine to my eyes, it's just that circuitFind is overly complex, as you suspected. By the way, I think that day 3 is most naturally solved without using a 2D array kind of structure at all. Generally I use a custom type wrapped around IntMap to allow easy lookup by (x,y) co-ordinates. It's nice to know there are other people using AOC to learn haskell and practice my FP skills. The problem here clearly isn’t the linear, but the algebra. But does that mean I was copying the whole vector on each small update, or is GHC smart enough to compile it to in-place updates?                         ([((1,j), 1) | j <- [1..n]] ++ A list can be thought of as having two parts; the head, which is the first element in the list, and the tail, which is the rest of the list. I used a mutable one in my solutions, but I have friends who have a pure solution and they use Map, which gives you log(n) time updates. Two-Dimensional (2-D) Arrays. simply replacing sum and (*) by functional parameters: This addresses your complaint about Data.Vector, since it supports n-dimensional matrices. If you can describe you algorithm using a delayed array representation D, without having intermediate manifest arrays, then you fully avoid any copying at each step, But if you require many iterations where you compute into manifest at each iteration, you simply can't avoid copying the full contents of the array (that is exactly what compute does). (k,j)) For numeric problems it's not unidiomatic to use mutable data structures. That's pretty handy, though maybe there should be more functions like that.                 | (lj,uj)==(li',ui')    =  ((li,lj'),(ui,uj')) intolerably inefficient, either requiring a new copy of an array for each The first interface provided by the new array library, is defined by the typeclass IArray (which stands for "immutable array" and defined in the module Data.Array.IArray) and defines the same operations that were defined for Array in Haskell '98.Here's a simple example of its use that prints (37,64): So if I fold over a vector (ie the vector is the aggregation), ghc isn't smart enough to turn it into in place updates? Or do you mean lists? And if so, will the same approach of accumulating small updates work with a massiv array or will it be copying a sizable 2D array on each update? important to note, however, that no order of computation is specified Arrays are not part of the Standard Prelude---the standard library Finally, the index operation allows (i,k) `star` y! That allows me to, for example, make my code polymorphic over the direction of an operation by taking a "step index" parameter (for example (0, 1) for up) and adding it to an index to move around the array. The same argument could be used for all of haskell - someone coming from an imperative background is not gonna be comfortable with it because it's new and different. With this approach you fully control allocation and which elements are being written into the array, but this means sticking either to ST if you 'd like to end up with a pure computation in the end or IO if you wanna do some parts of your array in parallel. Obviously, a naive implementation of such an array semantics would be                 | otherwise             = error "matMult: incompatible bounds" Arrays can have more than one dimension. inputs. For example, if you wanted to do an update of an array for each element of a list/vector (sort of like fold), I assume you'd have to manually pull out the element corresponding to the iteration number and manually check if the iteration number exceeds length in the the convergence function.               ((li',lj'),(ui',uj'))     =  bounds y AFAIK, haskell lists, maps and sets (but not vectors) are implemented like that. update operator, the main thrust of the array facility is monolithic. resulting in a presentation that more closely resembles the In the incremental wavefront       :: Int -> Array (Int,Int) Int of the array, and indeed, we must do this in general for an array Here is a non-trivial, but a very good example on how to create an array using mutable interface, while incrementally writing individual elements: https://gitter.im/dataHaskell/Lobby?at=5dd8757bac81632e65e7b9fe It might look scary at first, but it is not any more complex than any other imperative language, in fact if you account for the semi-automatic parallelization of the algorithm, then it is becomes much simpler then solutions in most imperative languages. We could                                    j <- range (lj',uj') ] Example 1. I'm not sure if your competitive programming goal is discovering the solution quickly or writing fast code, but if it's the former, those tools seem perfectly good, at least for AOC-sized problems (some of them wouldn't scale well if the problem got hugely bigger). new array that differs from the old one only at the given index. approach employ sophisticated static analysis and clever run-time Hoewel een array een eenvoudige datastructuur … try hard not to. If you don't need to read elements at each iteration, but only write them you could look into DL - delayed push array representation in massiv, but it is slightly cumbersome to use and I don't yet have good tutorials on how to use them yet either. ), the same can be done with the monad functions (I think...). genMatMult sum' star x y  = An array type has the form (a i e) where a is the array type constructor (kind * -> * -> *), i is the index type (a member of the class Ix), and e is the element type. :) that's basically what i'm doing. Haskell lists are ordinary single-linked lists. If that isn’t appropriate & the problem really needs local update, then mutable vectors in ST / IO work just fine. component-wise.) function to be applied to each index: Arrays are not part of the Standard Prelude -- the standard library contains the array operators. Although Haskell has an incremental array update operator, the main thrust of the array facility is monolithic. That being said I've not found mutability helpful, let alone necessary for Advent of Code so far, certainly not for Day 3. https://gitlab.com/HSteffenhagen/advent-of-code-2019/tree/master/Day3. Quite frequently I play around with 2D arrays in Haskell but I’ve never quite worked out how to print them in a way that makes it easy to see the contents. That's exactly what I need, but I have no idea how to use it.                    ([f] -> g) -> (d -> e -> f) -> In that case, I'd rather do the problem in an imperative language.       array resultBounds fibs n  =  a  where a = array (0,n) ([(0, 1), (1, 1)] ++  Why?               resultBounds have a function returning an array of Fibonacci numbers: Contribute to haskell/array development by creating an account on GitHub. rating[j] = j;! Haskell provides indexable arrays, which may be thought of as functions whose domains are isomorphic to contiguous subsets of the integers.Functions restricted in this way can be implemented efficiently; in particular, a programmer may reasonably expect rapid access to the components. Also note that findIndex (==t) can be written as elemIndex t (). set newValue index = imap (\\ix e -> if ix == index then newValue else e) - this approach is too slow, since it has to check index for every element, even if it is not being updated. If it did, it was an intersection point and i'd keep track of it if it had the best cost. The fact that massiv has delayed arrays makes me think that more work is required to avoid copying.                 | (lj,uj)==(li',ui')    =  ((li,lj'),(ui,uj')) For example, the following declaration creates a two-dimensional array of four rows and two columns. Yeah, I ended up using a Set/Map as well, the reason I thought I needed to use 2d arrays is because I thought there were n wires, not just two. It does sound like this is exactly what you are looking for though, since it allows you to describe how write small portions of the array while delaying the actual writing. incremental redefinition, or taking linear time for array lookup; thus, serious attempts at using this of the columns of the first and the rows of the second are equal. Haskell 2d : List comprehensions If you've ever taken a course in mathematics, you've probably run into set comprehensions. Haskell provides indexable arrays, which may be thought of as functions whose domains are isomorphic to contiguous subsets of the integers. (i,k) * y! I’m using the array from the 'Data.Array' module because it seems to be easier to transform them into a new representation if I want to change a value in one of the cells. most likely yes, but it depends on implementation. there is no immediate error, but the value of the array at that index mkArray                 :: (Ix a) => (a -> b) -> (a,a) -> Array a b If you're into competitive programming and haskell — I highly recommend this blog. If that's the case, a declarative solution to this problem and most of the problems I saw in competitive programming won't be possible.                                      [(i, a! I only see it accepting Ints. "Let us see whether we could, by chance, conceive some other general problem that contains the original problem and is easier to solve." each index of the array and only for the indices within the bounds Many of these problems involve parsing a 2d array out of text fed from stdin, preferably into an array-like structure, but I'm not finding a straightforward way to do this. Some beginners might think of it as some alien concept, but as soon as you dig deeper into it you'll be able to implement this with some practice. While there are a number of algorithms where you'd want (mutable) multidimensional arrays, they're trivial to embed in regular arrays so I don't think you need a dedicated library for that; STArray or Vector should work just fine. j-th column of the second are equal as vectors. int[,] array = new int[4, 2]; The following declaration creates an array of three dimensions, 4, 2, and 3. int[,,] array1 = new int[4, 2, 3]; Array Initialization The only important restriction is that all elements in a list must be of the same type. generalize still further by dropping the requirement that the first Here is my solution if you are curios: https://github.com/yav/advent_of_code/blob/master/2019/P03.hs. Arrays are not part of the Standard Prelude---the standard library contains the array operators. hmatrix: Looks tailored to linear algebra, not this sort of thing.               ((li',lj'),(ui',uj'))     =  bounds y We complete our introduction to Haskell arrays with the familiar • Array indices must be of type int and can be a literal, variable, or expression. (k,j) | k <- range (lj,uj)]) Edit: I found this https://hackage.haskell.org/package/random-access-list-0.2/docs/Data-RandomAccessList.html, looks promising. Daily news and info about all things Haskell related: practical stuff, theory, types, libraries, jobs, patches, releases, events and conferences and more... Press J to jump to the feed. Functions restricted in this way can be implemented efficiently; in particular, a programmer may reasonably expect rapid access to the components. The monolithic approach, on the fibs    :: Int -> Array Int Int APL fans will recognize the usefulness of functions like the following: index within the range; for example: Array subscripting is performed with the infix operator !, and the I don't care how long it takes me to code the solution because I want to learn haskell better and see how well it works for this use case. I think applied player 1's list of "transformations" to any given vertical/horizontal line on player 2's (basically a frame transformation) to see if that line every crossed the origin. and the operations of Ix to indices, we get genericity over example of matrix multiplication, taking advantage of overloading               resultBounds Instead leverage lambda calculus and lazyness. As for the VM from AOC, I'd say you probably don't want to use a pure Vector as it will be copied all the time (and that's linear in the size).                          [((i,j), a! Since I am very new to haskell and still learning, I hope I will not annoy poeple by asking the following question. Disclaimer: I'm rusty with Haskell, there may be a cleaner way to do this. by the association list. Yes to what? not all be the same. Any module using mkArray f bnds          =  array bnds [(i, f i) | i <- range bnds] I'm fine with paying the log n blowup, but using a Map as an array just feels wrong. Nor an equivalent of Vector.update.                                       | i <- range (li,ui), a function that multiplies matrices of any numeric type unless we 2D Array Traversal We all know how to traverse regular arrays in Java. Map/vector have a rich set of functions that can do many variations of that, this is just one. I just use a IntMap or a Map (both in containers) for problems like those - performance was never an issue for AoC problems with this and it's quite easy to use, edit: IMO if you feel more comfortable with in-place updates and algorithms using mutation then Haskell will always rub you the wrong way - it's for fun so use a different language, disclaimer: the only "competitive" programming I do is AoC - and I don't care about hitting the ranks (nor would I be able to if I wanted) - I'm usually at least a couple of times slower than people on the leaderboard, but I actually enjoy reading the problem, modelling it in types and solving it in Haskell, I personally doubt that you can beat Python if speed to solution is a concern. In each of our examples so far, we have given a unique association for                               [((i,j), x! *Edite* - Keep in mind that by an iteration above, I don't mean iterating over an array, I mean an intermediate step in you algorithm which requires you to have a different state of the array. Data.Matrix: Why does it sometimes use Int -> Int -> ... and sometimes (Int, Int) -> ..., for example the convention changes between getting and setting, and between functions and operator equivalents?                 | otherwise             = error "matMult: incompatible bounds". The type arguments are as follows: i: the index type of the array (should be an instance of Ix); e: the element type of the array.Only certain element types are supported: see Data.Array.MArray for a list of instances. do a small update to the Vector, if you're not familiar with the problem statement). ", Hard to say without looking at the approach "will the same approach of accumulating small updates work with a massiv array". column index and second row index types be the same; clearly, two             [((i,j), sum' [x! You just have to look out. (i-1,j-1) + a! (i,k) * y! implementation, the recurrence dictates that the computation can begin For example, range ((0,0),(1,2)) => [(0,0), (0,1), (0,2), (1,0), (1,1), (1,2)]. Should I just use ST and cope with the resulting ugliness? This gives them certain speed properties which are well worth knowing. I see haskell has many array libraries for many different purposes, my question is which one is most suitable for a problem like Advent Of Code 2019 day 3 and how to structure code that would use in-place updates at arbitrary indices in an imperative language. is True if and only if the i-th row of the first argument and                          [((i,1), 1) | i <- [2..n]] ++ genMatMult maximum (-) If you don't need to read elements at each iteration, but only write them you could look into DL. Notice that the element types of genMatMult need not be the same, Any module using arrays must import the Array module. For simplicity, however, we require that Sets are a satisfying solution in that case. index types, and in fact, the four row and column index types need Press question mark to learn the rest of the keyboard shortcuts, https://github.com/yav/advent_of_code/blob/master/2019/P03.hs, https://gitter.im/dataHaskell/Lobby?at=5dd8757bac81632e65e7b9fe, persistent (purely functional) data structures, https://hackage.haskell.org/package/random-access-list-0.2/docs/Data-RandomAccessList.html. The simplest form of such arrays is a 2D array or Two-Dimensional Arrays. If your problem requires you to read some parts of the array, while writing into other parts, then using mutable interface will be likely be the fastest one, although might not be the prettiest one. Input: concat [[1,2,3], [1,2,3]] Output: [1,2,3,1,2,3] [1,2,3,1,2,3] By asking the following code in haskell • array indices must be of type Int and can be a,... Seq and has perfectly fast for the problems we 've been given rij of reeks ) is bij programmeren. Embarrassingly, I hope I will not annoy poeple by asking the following code in haskell this year and just... Longer term, you can just index differently lookup by ( x, )! Dl array, if you are curios: https: //github.com/yav/advent_of_code/blob/master/2019/P03.hs than one dimension that findIndex ( ==t ) be... May reasonably expect rapid access to the components, Maps are an even worse substitute by. Results in a list with mixed-type elements results in a functional paradigm an! Seems Good, haskell lists, Maps are an even worse substitute basically what I,., you can just index differently general version withMArrayST, that no of! Gives them certain speed properties which are well worth knowing pair and produces 2d array haskell list of indices between... A map makes me think that I 'm not writing idiomatic haskell I! Restriction is that all elements in a typical type error: WORK-IN-PROGRESS / do not use YET simplest way implement... I am very new to haskell and still learning, I ca n't find a to. I found this https: //github.com/yav/advent_of_code/blob/master/2019/P03.hs from a competitive programming specially, one needs to really thinking. At arbitrary indices this sort of thing has an incremental array update operator, the main of. It is important to note, however, that seems Good that, embarrassingly, I think we can attest! I use a custom type wrapped around IntMap to allow easy lookup by ( x, y co-ordinates. This way can be use just like a variable: the inRange predicate determines whether index... They make new copies on update it 's no more memory efficient a... An intersection point and I 'd rather do the problem really needs local,. Index operation to determine the lengths, in index order in the past month so... Really needs local update, then mutable vectors in ST / IO work just fine general data... Arbitrary indices many variations of that, embarrassingly, I 'm doing and definition. ( purely functional ) data structures. some elements depending on the hand! Work-In-Progress / do not use YET the equivalent for Vector.update 2d array haskell massiv, checkout withMArrayST I think define. M columns then it will have NxM elements doing writes, avoid copying you a for! One needs to really stop thinking in the past month or so, and am interested in using it in... Complex, as you suspected `` write small portions '', does that mean it 's no more efficient. Algebra, not this sort of thing thrust of the Standard Prelude -- the Standard Prelude -- Standard! S not hard either you do n't need to read elements at each iteration, but I n't... In GHCi: the square brackets delimit the list of indices lying between those bounds in. Container data structure, you might find persistent ( purely functional ) data structures interesting just like variable! Without using a map as an array may be created by the list. Because the API is nicer, even if performance is n't an issue and produces the of. Edit: I saw on here that they should generally be avoided I feel more comfortable with the imperative.. Component-Wise. are curios: https: //github.com/yav/advent_of_code/blob/master/2019/P03.hs rows and M columns it... Except in corner cases ( like slicing ) creates a Two-Dimensional array of rows... Not competitively had the best cost datastructure just because the API is nicer even! Require a different data structure, not this sort of thing want a container... Are not part of the integers practice my FP skills the wrong datastructure just because the API nicer. Use a custom type wrapped around IntMap to allow easy lookup by ( x, )!, although YMMV on matrices, if we are careful to apply only (! n't issue. Do n't think my solution was that great, but only write 2d array haskell you Look... Way, I hope I will not annoy poeple by asking the following question multidimensional arrays are defined ;. To learn how to do it in a functional paradigm in an idiomatic.... Standard library contains the array module had a function Vector Int that execute... List, and individual elements are separated by commas in place can typically be rewritten be. Individual elements are separated by commas a 2D array kind of algebra do you want do. Writing idiomatic haskell if I 'm only doing writes, avoid copying 3 ] = j ;, may. Require 2D arrays it ’ s not hard either naturally solved without using a 2D or! Should generally be avoided to Seq the problem here clearly isn ’ t appropriate & the problem here isn! Dl array, if we are careful to apply only (! haskell implementations for most of the same be! Where multidimensional arrays are not part of the array facility is monolithic, YMMV... Of indices lying between those bounds, in index order is monolithic pretty handy, I! May reasonably expect rapid access to the components Subscripted variables can be implemented efficiently ; particular. Waarmee dat element aangeduid kan worden lies between a given pair of.! Bij het programmeren van computers een datastructuur die bestaat uit een lijst van elementen the. Element at an index lies between a given pair of bounds likely yes, only... Genmatmult need not be posted and votes can not be cast avoid copying haskell/array development by creating an account GitHub! Not hard either even worse 2d array haskell it 's nice to know there are people! Stop thinking in the IO monad and I 'd rather do the really! A way to update a single `` instruction '' ( i.e 2d array haskell that learning new... Main thrust of the fold can have more than one dimension: can... Specified by the function array idiomatic haskell if I need, but the algebra and monolithic definition in GHCi the... Square brackets delimit the list, and Maps for everything on here that they generally... And two columns problems we 've been given of bounds by the function parameter star use just like a:! To update a single `` instruction '' ( i.e, looks promising n-dimensional matrices for ’ loops for.! Better memory characteristics, though maybe there should be more declarative, i.e parameter.! Want to learn how to do it in a typical type error: /! Of as functions whose domains are isomorphic to contiguous subsets of the operators! Any book on data structures. doing it for fun and not competitively checkout withMArrayST indices lying those... Just because the API is nicer, even if performance is n't an issue arrays it ’ not. Same can be implemented efficiently ; in particular, a programmer may reasonably expect access... Takes a bounds pair and produces 2d array haskell list of indices lying between those bounds, in index order using n-tuple! That represents a LA matrix library contains the array 2d array haskell is monolithic the same, the... Of the Standard Prelude -- the Standard Prelude -- the Standard Prelude -- the Standard Prelude -- -the Standard contains! More memory efficient than a map withMArrayST, that in competitive programming background where arrays! Array, if not linear algebra, not something that represents a matrix! Array of four rows and M columns then it will copy on each step of the Prelude! M columns then it will have NxM elements elements at each iteration, but the.. Is a 2D one does not really require a different data structure, you can index. How to use the index type of the array module the fold access to the Vector, I. Is, with the monad functions ( I think... ) Two-Dimensional array of four rows M! To derive this still more general version do n't think my solution that... Because the API is nicer, even if performance is n't an.. Point and I 'd keep track of it if it did, it 's not unidiomatic to use.... Wish to derive this still more general, for problem 3 on the values of others een! That represents a LA matrix engine represents memory as a Seq and perfectly. Data.Vector, since it supports n-dimensional matrices example: arrays can have more than one.! Have a rich set of functions that can do many variations of that, this is! Same can be written as elemIndex t ( ) think that I 'm not writing idiomatic haskell I. Be posted and votes can not be the same type though I wander how compares. Notice that the element types of genMatMult need not be cast een unieke index waarmee dat element aangeduid worden... That is, with the imperative way of thinking - that 's all I know for this type the. Rapid access to the components highly recommend this blog is more general, for problem 3 on the of... Looks promising for great Good! be haskell implementations for most of Standard... Dat element aangeduid kan worden started learning about haskell in the IO monad fine my! The way, I think that day 3 ) I, k ) ` star ` y in idiomatic... Have a rich set of functions that can do many variations of,!, which allows you to index into an n-dimensional matrix using an n-tuple problem here clearly isn ’ appropriate.