Daniel-Diaz / matrix

A Haskell native implementation of matrices and their operations.
BSD 3-Clause "New" or "Revised" License
35 stars 31 forks source link

Missing Applicative instance #17

Closed shoooe closed 8 years ago

shoooe commented 9 years ago

Sounds like a Matrix a is a perfect fit for an Applicative (and possibly even Monad) instance. Data.Vector also has such instances, and given that the former is implemented in terms of the latter, the actual implementation of these instances should be trivial.

What am I missing?

octopuscabbage commented 9 years ago

Applicative I can see, although it would have to be a partial function because it will only work on matricies of the same dimensions.

I don't see a monad instance because how would one concatenate matricies in a sane way.

hherman1 commented 8 years ago

I'd say >> ~ Tensor Product,

As far as concatenation

Monoid a => Monoid (Matrix a) Pointwise mappend

octopuscabbage commented 8 years ago

I'd say >> ~ Tensor Product,

I'm not familiar with that operation so I can't really say if that makes sense or not.

Monoid a => Monoid (Matrix a) Pointwise mappend

makes sense, for different sized matrices we could just <> mempty.

hherman1 commented 8 years ago

http://www.sharetechnote.com/image/EngMath_TensorProduct_01.png

Similar to how list does >>, but makes sense in 2D

octopuscabbage commented 8 years ago

What happens if the matrices are differently sized? Would they just be mempty?

octopuscabbage commented 8 years ago

I plan to at least write the monoid instance in a few minutes and the tensor product if I can figure it out.

hherman1 commented 8 years ago

its a_ii * B, dimensions dont matter for tensor

On Wed, Jan 20, 2016 at 3:52 PM, Chris Denniston notifications@github.com wrote:

I plan to at least write the monoid instance in a few minutes and the tensor product if I can figure it out.

— Reply to this email directly or view it on GitHub https://github.com/Daniel-Diaz/matrix/issues/17#issuecomment-173372513.

octopuscabbage commented 8 years ago

ohh i see that now

octopuscabbage commented 8 years ago

The problem being that applicative is a requirement for monad. Maybe we can work backwards from <*> being ap?

octopuscabbage commented 8 years ago

would applicative just be tensor multiplication but instead of multiplication be function application?

shoooe commented 8 years ago

I guess we can close this now, right?

octopuscabbage commented 8 years ago

I suppose once the PR gets merged but we should probably take our commentary there.

Daniel-Diaz commented 8 years ago

Closing this. See https://github.com/Daniel-Diaz/matrix/pull/27