Skip to content
This repository has been archived by the owner on Sep 7, 2018. It is now read-only.

Comonad instance for Vec #71

Open
ggreif opened this issue Aug 31, 2016 · 0 comments
Open

Comonad instance for Vec #71

ggreif opened this issue Aug 31, 2016 · 0 comments

Comments

@ggreif
Copy link
Contributor

ggreif commented Aug 31, 2016

This is a (low-prio) feature request. Comonad interface is very convenient for looking at a vector from all perspectives (indices) at once. It allows tranformations of the entire vector by allowing the mapping to peek into neighbouring elements . Think blurring of pixels 0, or other image transformations 1. Writing down the instance is easy:

{-# language DeriveFunctor, TupleSections #-}

module CoVec where

import CLaSH.Prelude hiding (extend)
import Control.Comonad

newtype CoVec n a = CoVec (Index n, Vec n a) deriving (Eq, Show, Functor)

instance KnownNat n => Comonad (CoVec n) where
  extract (CoVec (i, v)) = v !! i
  duplicate (CoVec (i, v)) = CoVec (i, CoVec . (,v) <$> indicesI)

The question is whether one wants to add the Comonad dependency.

Another problem might be the consumption of logical resources (LUTs). I did not evaluate this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant