Skip to content

Instantly share code, notes, and snippets.

@Dubhead
Created March 16, 2012 08:21
Show Gist options
  • Save Dubhead/2049097 to your computer and use it in GitHub Desktop.
Save Dubhead/2049097 to your computer and use it in GitHub Desktop.
matrix product in Pure
% pure -i
Pure 0.52 (x86_64-unknown-linux-gnu) Copyright (c) 2008-2012 by Albert Graef
(Type 'help' for help, 'help copying' for license information.)
Loaded prelude from /usr/local/lib/pure/prelude.pure.
> sum = foldl (+) 0;
> dot x::matrix y::matrix = sum $ zipwith (*) (rowvector x) (rowvector y);
> x::matrix * y::matrix = {dot u v | u = rows x; v = cols y};
> a = {1, 2, 3; 1, 2, 3; 1, 2, 3};
> b = {1, 2, 3, 4; 1, 2, 3, 4; 1, 2, 3, 4};
> a * b;
{6,12,18,24;6,12,18,24;6,12,18,24}
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment