lens

Shapeless: generic lens parameterized by case class or field

匿名 (未验证) 提交于 2019-12-03 01:17:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Based on: import shapeless . _ case class Content ( field : Int ) lens [ Content ] >> 'field I am trying to make a lens-creating method, something along: def makeLens [ T <: Product ]( s : Symbol ) = lens [ T ] >> s But it seems non-obvious. Is it possible to do? If not, the end result I'm trying to achieve is a generic method for updating nested Maps with case-class contents, e.g.: import scalaz . _ import Scalaz . _ import PLens . _ import shapeless . _ import shapeless . contrib . scalaz . _ def nestedMapLens [ R , T <: Product

Haskell: Reusing FromJSON instances with lenses, lens-aeson, and nested JSON

柔情痞子 提交于 2019-12-03 01:15:30
I have been playing with Aeson and the lens package (lens-aeson, migrated from the core lens package), and have been sruggling to get them to work together. As a toy example, I have a type: data Colour = Yellow | Green | Blue and the FromJSON instance: instance FromJSON Colour where parseJSON (String s) = return $ case s of "blue" -> Blue "green" -> Green _ -> Yellow parseJSON _ = mzero So far so good. Now, say I have some nested JSON data come in that I want to extract just this out of: { "info": { "colour": "yellow" }, /* other props */ } I don't care about the rest, only this "colour" value

camera

匿名 (未验证) 提交于 2019-12-03 00:39:02
一、camera成像原理: 景物通过镜头(LENS)生成的光学图像投射到图像传感器(Sensor)表面上,然后转为模 拟的电信号,经过 A/D(模数转换)转换后变为数字图像信号,再送到数字信号处理芯片 (DSP)中加工处理,再通过 IO 接口传输到 CPU 中处理,通过 LCD 就可以看到图像了。 图像传感器(SENSOR)是一种半导体芯片,其表面包含有几十万到几百万的光电二极 管。光电二极管受到光照射时,就会产生电荷。 目前的 SENSOR 类型有两种: 1)CCD(Charge Couple Device), 电荷耦合器件,它是目前高像素类 sensor 中比较成熟 的成像器件,是以一行为单位的电流信号。 2)CMOS(Complementary Metal Oxide Semiconductor),互补金属氧化物半导体。CMOS 的信号是以点为单位的电荷信号,更为敏感,速度也更快,更为省电。 ISP 的性能是决定影像流畅的关键,JPEG encoder 的性能也是关键指标之一。而 JPEG encoder 又分为硬件 JPEG 压缩方式,和软件 RGB 压缩方式。 DSP 控制芯片的作用是:将感光芯片获取的数据及时快速地传到 baseband 中并刷新感 光芯片,因此控制芯片的好坏,直接决定画面品质(比如色彩饱和度、清晰度)与流畅度。 二、常见camera得数据输出格式

PHP十六进制颜色转RGB颜色值

匿名 (未验证) 提交于 2019-12-02 22:11:45
/** * 十六进制转RGB * * @param string $color 16进制颜色值 * @return array */ public static function hex2rgb($color) { $hexColor = str_replace('#', '', $color); $lens = strlen($hexColor); if ($lens != 3 && $lens != 6) { return false; } $newcolor = ''; if ($lens == 3) { for ($i = 0; $i < $lens; $i++) { $newcolor .= $hexColor[$i] . $hexColor[$i]; } } else { $newcolor = $hexColor; } $hex = str_split($newcolor, 2); $rgb = []; foreach ($hex as $key => $vls) { $rgb[] = hexdec($vls); } return $rgb; } 文章来源: PHP十六进制颜色转RGB颜色值

Ramda js: lens for deeply nested objects with nested arrays of objects

試著忘記壹切 提交于 2019-12-02 18:14:50
Using Ramda.js (and lenses), I want to modify the JavaScript object below to change "NAME:VERSION1" to "NAME:VERSION2" for the object that has ID= "/1/B/i". I want to use a lens because I want to just change one deeply nested value, but otherwise retain the entire structure unchanged. I don't want to use lensIndex because I never know what order the arrays will be in, so instead, I want to "find" the object in an array by looking for its "id" fields. Can I do this with lenses, or should I do it a different way? { "id": "/1", "groups": [ { "id": "/1/A", "apps": [ { "id": "/1/A/i", "more nested

How to combine lenses in “parallel”

北战南征 提交于 2019-12-01 17:31:11
I'm new to the excelent Control.Lens and I'm trying to combine 2 lens in "parallel" (not in sequence) like I would do with `Control.Arrow.&&&). If I take the example from the lens documentation: `data Foo a = Foo { _baz :: Int, _bar :: Int, a } I would like to be able to do stuff like : >> let foo = (bar &&& baz) .~ (1, 20) $ Foo undefined undefined "FOO" >> foo ^. (bar &&& baz) (1, 20) I've looked everywhere and I could not find a way to do so. Is that because : (&&&) exist with another name and I missed it. It's useless. I should not need it, therefore nobody bothered implementing it. It's

字符串hash模板

一笑奈何 提交于 2019-12-01 10:13:35
简介:    做hdu4300看到的题解,除了kmp还可以用字符串hash做 模板: 1 typedef unsigned long long ull; 2 const int maxn=100000+10; 3 const ull base = 163; 4 char s[maxn],t[maxn]; 5 ull h1[maxn],h2[maxn]; 6 ull p[maxn]; 7 void init(){ ///处理hash值 8 p[0] = 1; 9 h1[0] = h2[0]=0; 10 int n = strlen(s+1); ///字符串从1开始读 11 for(int i = 1; i <=100000; i ++) p[i] =p[i-1] * base; 12 for(int i = 1; i <=n; i ++) hash[i] = hash[i - 1] * base + (s[i] - 'a'); 13 } 14 ull geth(int l, int r, ull g[]){///取出g里l - r里面的字符串的hash值 15 return g[r] - g[l - 1] * p[r - l + 1]; 16 } View Code 字符串hash: 1 #include<bits/stdc++.h> 2 #define numm ch-48 3

How would I use lens in Haskell to duplicate Python's enumerate?

眉间皱痕 提交于 2019-12-01 06:46:35
Python's enumerate on lists can be written as zip [0..] . I looked at Control.Lens.Traversal and Control.Lens.Indexed, but I couldn't figure out how to use lenses to generalize this to any reasonable container (I hesitate to say "Traversable"). I'm guessing itraverse or itraverseOf is key. If you're using a container that is an instance of FunctorWithIndex then you can simply use imap (,) : > imap (,) "abc" [(0,'a'),(1,'b'),(2,'c')] But if the index isn't the position this won't work: > let m = Map.fromList [('a', "foo"), ('b', "bar"), ('c', "foobar")]) > imap (,) m fromList [('a',('a',"foo"))

How to make the product of two lenses?

◇◆丶佛笑我妖孽 提交于 2019-12-01 04:21:48
If I have two lenses: foo :: Lens' X Foo bar :: Lens' X Bar Is there a way to construct a product lens: foobar :: Lens' X (Foo, Bar) foobar = ... foo bar or is it impossible? In general case, this is impossible. Probably the most common case when you have lenses to different fields of the record, the lenses are disjoint, so you can make a lawful lens. But in general it's not true. This is why the combinator is not provided in the libraries, even it would be easy to write. Assume lensProd exists. It's enough to take the same lens twice: _1 :: Lens' (a, b) a -- Simpler type badLens :: Lens' (a,

Haskell: Template Haskell and the scope

放肆的年华 提交于 2019-12-01 03:27:11
This code is compiled fine: data None = None { _f :: Int } type Simpl = Env type Env = Int However, I got an error with this code: {-# LANGUAGE TemplateHaskell #-} import Control.Lens data None = None { _f :: Int } type Simpl = Env makeLenses ''None type Env = Int Error: Not in scope: type constructor or class `Env' I just added a single line makeLenses ''None between type declarations. This means TemplateHaskell code could change the scope of type constructor? Does anyone know the detail about this issue(or how to avoid this problem)? If you reorder your code as follows, it works: {-#