I am not going to waste time right now to translate your code into Haskell, but I am going to criticize the code that you have and offer some tips.
First of all, the type [Foo]
means "list Foo". And by "list" I mean an immutable, simply connected list. The Matrix
type makes perfect sense: the matrix is a list of "rows", where the "row" is a Double list. However, your Vector
type does not make sense. Perhaps you wanted to say:
type Vector = [Double] type Matrix = [Vector]
Return to the listings in general. Lists can be indexed using the operator !!
. for instance
["foo", "bar", "baz"] !! 1 == "bar"
You can add an element with :
(pronounced "cons")
"quux" : ["foo", "bar", "baz"] == ["quux", "foo", "bar", "baz"]
You can add two lists with ++
[1,2] ++ [3,4] == [1,2,3,4]
Thus, you can add an element with list ++ [x]
, although this is inefficient and not recommended. In fact, indexing is also quite slow. If you need efficient indexing and adding, instead of Data.Sequence . But as a newbie, I would not recommend you worrying about efficiency for a long time.
I would advise you to learn a little more Haskell before trying to translate the code; your Python algorithm uses a mutation that is generally avoided in Haskell, although this is certainly possible. After you get a little more experience with Haskell types and functions, you might be interested in the package.