{-# OPTIONS --safe #-}
module Cubical.Algebra.Module.Instances.FinMatrix where

open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.SIP using (str; ⟨_⟩)

open import Cubical.Functions.FunExtEquiv using (funExt₂)

open import Cubical.Data.Nat using ()

open import Cubical.Algebra.Matrix
open import Cubical.Algebra.Ring
open import Cubical.Algebra.Module

open import Cubical.Algebra.Module.Instances.FinVec

module _ {} (R : Ring ) {m n : } where

  private
    open module R' = RingStr (str R) renaming (_+_ to _+r_; -_ to -r_)
    module FV {n} = LeftModuleStr (str (FinVecLeftModule R {n}))
  open LeftModuleStr

  FinMatrixLeftModule : LeftModule R 
  fst FinMatrixLeftModule = FinMatrix  R  m n
  0m  (snd FinMatrixLeftModule) = λ _        FV.0m
  _+_ (snd FinMatrixLeftModule) = λ xs ys x  xs x FV.+ ys x
  -_  (snd FinMatrixLeftModule) = λ xs x     FV.- xs x
  _⋆_ (snd FinMatrixLeftModule) = λ r xs x   r FV.⋆ xs x
  isLeftModule (snd FinMatrixLeftModule)    = isRLeftModule
    where
    isRLeftModule : IsLeftModule R _ _ _ _
    isRLeftModule = makeIsLeftModule
      (isSetΠ λ _  FV.is-set)
       _ _ _  funExt₂ λ _ _  R'.+Assoc _ _ _)
       _      funExt₂ λ _ _  R'.+IdR _)
       _      funExt₂ λ _ _  R'.+InvR _)
       _ _    funExt₂ λ _ _  R'.+Comm _ _)
       _ _ _  funExt₂ λ _ _  sym (R'.·Assoc _ _ _))
       _ _ _  funExt₂ λ _ _  ·DistR+ _ _ _)
       _ _ _  funExt₂ λ _ _  ·DistL+ _ _ _)
       _      funExt₂ λ _ _  R'.·IdL _)