by shigemk2

当面は技術的なことしか書かない

予習メモ #functional_shibuya

予習

www.shigemk2.com

6章 純粋関数型の状態

  • 乱数の生成

6.1 副作用を使った乱数の生成

  • scala.util.Random
  • 状態の更新は副作用として実行されるため、これらのメソッドは参照透過ではありません

6.2 純粋関数型の乱数の生成

  • 次の状態の計算を、プログラムの他の部分に対する新しい状態の通知から切り離す
  • カプセル化
  • 線型合同法(linear congruential generator)

f:id:shigemk2:20150620180325p:plain

6.3 ステートフル API の純粋化

  • API に実際に何かを変化させるのではなく、次の状態を計算させる
  • 純粋関数を使って次の状態を計算すると、データを実際にその場で変化させることができないため、効率性が低下する
  • 純粋関数を使ったプログラミングにより、設計空間は大幅に単純化

6.4 状態の処理に適した API

  • 状態アクションまたは状態遷移
  • コンビネータとは、後ほど定義する高階関数

  • 6.4.1 状態アクションの結合

  • 6.4.2 入れ子の状態アクション

6.5 状態アクションデータ型の一般化

  • 状態アクションを処理するための汎用目的の関数であり、状態の型を特別扱いしません
  • 状態を扱う計算、あるいは状態アクション、状態遷移、さらにはステートメントの省略形

6.6 純粋関数型の命令型プログラミング

  • 命令型プログラミングのパラダイムでは、プログラムとはずらりと並んだステートメントのこと であり、ステートメントはそれぞれプログラムの状態を変化させる可能性
  • 関数型プログラミングが副作用のないプログラミングにすぎない

6.7 まとめ

  • 考え方は単純で、引数として状態を受け取る純粋関数を使用し、結果とともに新しい状態を返します

lm-sensorsを使おう

lm-sensors - ArchWiki

マシンのCPUの温度などをモニタリングするパッケージのこと。 こいつをFedora20にいれてみる。

インストール。

yumで入ります。

sudo yum install -y lm_sensors lm_sensors-devel

設定。

sensors-detectで、最初の設定を自動的におこなうことができる。 あんまり理由がないので、とりあえず全部Yesにしておく。

$ sudo sensors-detect                             [122/1968]
# sensors-detect revision 6170 (2013-05-20 21:25:22 +0200)
# System: LENOVO 3680KE5 [ThinkPad X201] (laptop)

This program will help you determine which kernel modules you need
to load to use lm_sensors most effectively. It is generally safe
and recommended to accept the default answers to all questions,
unless you know what you're doing.

Some south bridges, CPUs or memory controllers contain embedded sensors.
Do you want to scan for them? This is totally safe. (YES/no): yes
Silicon Integrated Systems SIS5595...                       No
VIA VT82C686 Integrated Sensors...                          No
VIA VT8231 Integrated Sensors...                            No
AMD K8 thermal sensors...                                   No
AMD Family 10h thermal sensors...                           No
AMD Family 11h thermal sensors...                           No
AMD Family 12h and 14h thermal sensors...                   No
AMD Family 15h thermal sensors...                           No
AMD Family 15h power sensors...                             No
AMD Family 16h power sensors...                             No
Intel digital thermal sensor...                             Success!
(略)
Now follows a summary of the probes I have just done.
Just press ENTER to continue: yes^H^H

Driver `coretemp':
  * Chip `Intel digital thermal sensor' (confidence: 9)

Do you want to overwrite /etc/sysconfig/lm_sensors? (YES/no): yes
Unloading i2c-dev... OK

実行。

temp1とかがCPUの温度で、100度を超えるとやばいみたいな情報が見て取れる。

$ sensors
acpitz-virtual-0
Adapter: Virtual device
temp1:        +55.0°C  (crit = +100.0°C)

thinkpad-isa-0000
Adapter: ISA adapter
fan1:        3479 RPM
temp1:        +55.0°C  
temp2:         +0.0°C  
temp3:         +0.0°C  
temp4:         +0.0°C  
temp5:         +0.0°C  
temp6:         +0.0°C  
temp7:         +0.0°C  
temp8:         +0.0°C  

coretemp-isa-0000
Adapter: ISA adapter
Core 0:       +52.0°C  (high = +95.0°C, crit = +105.0°C)
Core 2:       +51.0°C  (high = +95.0°C, crit = +105.0°C)

感想。

Linuxですから、本当はいろいろ便利パッケージや便利アプリがあるかもしれませんがね。