Questions tagged [representable]
17 questions
5
votes
2 answers
When is Ap's Num instance lawful?
Consider this type:
newtype Ap f a = Ap (f a)
instance (Applicative f, Num a) => Num (Ap f a) where
(+) = liftA2 (+)
(*) = liftA2 (*)
negate = fmap negate
fromInteger = pure . fromInteger
abs = fmap abs
…

Joseph Sible-Reinstate Monica
- 45,431
- 5
- 48
- 98
5
votes
1 answer
Lenses over Comonads or Representable
Here's a more specific variant of this question: Mutate only focus of Store Comonad?, for the benefit of not asking more than one question at once.
Are there any lenses compatible with Control.Lens which allow me to interact with the focus of a…

Chris Penner
- 1,881
- 11
- 15
4
votes
1 answer
What is the role of Haskell's evaluation strategy in Memoization via Representable
The article Memoization via Representables does a great job at explaining how to memoize recursive functions via Representables. It starts by implementing the Fibonacci sequence as a fixed point of fibOp:
fibOp :: Num a => (Natural -> a) -> (Natural…

michid
- 10,536
- 3
- 32
- 59
3
votes
2 answers
How to write reverseT without using List?
I need an alternative to reverseT that doesn't use toList.
Obviously, this code is incorrect, but demonstrates the idea I was pursuing:
reverseF
:: (Foldable f, Representable f, Num (Rep f))
=> f a -> f a
reverseF f = tabulate $ \ix -> index f $…

dbanas
- 1,707
- 14
- 24
3
votes
1 answer
How to write a Representable instance using only Distributive properties?
Say I've got a Distributive instance written for some complex custom type, Foo.
Is it possible to write Foo's Representable instance using only the properties available from its Distributive instance? And, if not, then why is Distributive a…

dbanas
- 1,707
- 14
- 24
3
votes
1 answer
Make RoR nested representable into an array
In using the representable gem, I am looking to nest an object within an array, with that array only having one object. I can't see to figure out how to accomplish this. Any ideas? The reason for this is due to how Google Tag Manager handles…

Du3
- 1,424
- 6
- 18
- 36
3
votes
1 answer
Options grape representer
I am working on a rails API with Representers, using the following gems: Grape, Roar and Grape-Roar
Now, I try to add conditions to include (or not include) certain properties in my representer based on a condition I pass from my API endpoint as…

PSR
- 513
- 6
- 16
2
votes
0 answers
Quick Look preview via QLpreviewcontroller in Swiftui
Hi how do you make QuickLook usable in swiftui?
You have to implement QLpreviewcontroller with Representable. How do you do this?
I have some pdfs that are local and i wanted to use Bundle to locate them and have the pdfs shared to email and text…

CoffeeTree
- 21
- 3
2
votes
0 answers
How to use the singletons library to define a HasRep instance for existentially quantified types?
I'd like to use existentially sized image windows for a couple of reasons:
I'd like to pack different size windows into the same list.
I'd like to make a Zip instance for my window type.
I'm using this code to do this:
-- | A "matrix" represented…

dbanas
- 1,707
- 14
- 24
1
vote
1 answer
Set Initial View Offset for UITextView in SwiftUI
I am stumped on where to inject an initial content offset for a TextView created as a representable in SwiftUI. Here is the TextView code, followed by the ContentView that uses it. My objective is to be able to reposition a long text view back to…

Russ
- 467
- 3
- 10
1
vote
1 answer
How to go from a value of a finite discrete type to a (Finite n) and back, using the type's derived Generic instance, in Haskell?
I have a library that currently demands of users that they provide a helper function with type:
tEnum :: (KnownNat n) => MyType -> Finite n
so that the library implementation can use a very efficient sized vector representation of a function with…

dbanas
- 1,707
- 14
- 24
1
vote
0 answers
Mutate only focus of Store Comonad?
I'm using Control.Comonad.Representable.Store to represent a grid object for a game; the grid is: type Grid = Store (Compose Vector Vector) a; where Vector has a representable instance indexed by Int.
This allows me to use comonadic extend and…

Chris Penner
- 1,881
- 11
- 15
1
vote
0 answers
Representable gem: trouble handling nested documents (hashes)
I'm using the Representable gem and am following the instructions in the readme for accessing properties in a nested document.
Representer and test:
# app/representers/nhl/game_representer.rb
require 'representable/hash'
module…

sixty4bit
- 7,422
- 7
- 33
- 57
0
votes
1 answer
How to represent object properties in given context?
I am looking for a solution to my problem I have a relation => Company has_many Councils, through CouncilCompany.
And I would like to display Company in context of given Council, so if CouncilCompany has name property present display it over default…

tomekfranek
- 6,852
- 8
- 45
- 80
0
votes
1 answer
Trailblazer Representable Change Property Name with Variable
I would like to pass in a string variable that will be used as the property name.
For example, if I have the variable property_name, which contains a string, I want to do something like this:
property :property_name, type: String, getter: ->(_) {…

eclaire211
- 101
- 2
- 12