SCM Boot Camp in Nagoya ã«è¡ã£ã¦ããã»ã»ã»ã¨è¦ãããã SML# ã®å¤ç¸ã¬ã³ã¼ãã®è©±
SCM Boot Camp ã«ã¤ãã¦ã¯ä»ã®åæ¹ãæ¸ãã¦ãããã¨æãã®ã§ãéã話ãæ¸ãã¾ãã
SCM Boot Camp éå§åã®éè«ãæ親ä¼ã§è©±é¡ã«ãªã£ã SML# ã§ããã幸ãä¸å¹¸ã .NET ç³»ã®è¨èªã¨åéããããã¡ã§ãã
ã§ã SML# ã® # ã¯ãå¤ç¸ã¬ã³ã¼ããæ±ãéã«åºã¦ãã # ãå
ã«ãªã£ã¦ãã¾ãã
ã¡ãªã¿ã«ã.NET Framework 㯠2000 å¹´ãªãªã¼ã¹ãSML# ã®å身ã§ãã (ã§ããã®ããªï¼) SML# of Kansai ã 1993 å¹´éçºã¨è¨ããã¨ã§ããªã㨠.NET ãããæ´å²ãããã®ã§ãã
ã§ãæ親ä¼ã§ SML# ãããããã£ã¦è©±ãããããå¤ç¸ã¬ã³ã¼ãï¼ä½ããç¾å³ããã®ï¼ãã£ã¦äººãã»ã¨ãã©ã ã£ãã®ã§ã(ã¶ã£ã¡ããèªåããããªç解ãã¦ãªãã§ããã©) SML# ã®å¤ç¸ã¬ã³ã¼ããç´¹ä»ãã¦ã¿ããããªãã¨æãããã®ã¨ã³ããªãæ¸ãã¦ãã¾ãã
ç°å¢ã¯ Windows ãæ³å®ãã¦ãå¨è¾ºç°å¢ã®æ§ç¯ã¨ SML# å¦çç³»ã®ã¤ã³ã¹ãã¼ã«ããå§ããã®ã§ãåå¿è
ã«ãå®å¿ã§ãããã¶ãã
F# ã OCaml ã®å
¥éã¬ãã«ã®ç¥èãåæã¨ãã¦ãã¾ãã
ã»ã»ã»ãã£ã¨ããããªã¨ããã«ã¡ããã©ããè¨äºãï¼(ã
F#で初めての関数型プログラミング − @IT
SML# ã£ã¦ä½ï¼
Standard ML ã¨ããéçåä»ãã®é¢æ°åè¨èªãæ¡å¼µããè¨èªã§ã主ã«æ±å大å¦ã®å¤§å ç 究室ãéçºãã¦ãã¾ãã
SML# ã®ç¹å¾´ã¨ãã¦ã¯ã
- å¤ç¸ã¬ã³ã¼ã
- C è¨èªã¨ã®é£æºã®å®¹æã
- åå²ã³ã³ãã¤ã«
- ãªãã¸ã§ã¯ãã移åãããªã GC
çãããããã¾ãã
C è¨èªã¨ã®é£æºã®å®¹æãã¯çµæ§è¡æçã§ãããä»åã®ã´ã¼ã«ã¯å¤ç¸ã¬ã³ã¼ãã§ããã§ã C è¨èªã¨ã®é£æºã®å®¹æãã«ã触ãã¾ãã
ãã®ã¨ã³ããªã§ã¯ã©ãã¾ã§ã SML ã§ã©ãããã SML# ãªã®ããã¨ããåºå¥ã¯è¡ãã¾ããã
ãSML# ã§ã¯ãã¨æ¸ããã¦ããã¨ãã¦ããå®ã¯ããåãªã SML ã§ãã§ããããã£ã¦å ´åãããã¾ãã
ç°å¢æ§ç¯
SML# ã Windows ã«ã¤ã³ã¹ãã¼ã«ããããã«ã¯ãã¾ã㯠MinGW 㨠MSYS ã®ç°å¢ãæ´ããå¿
è¦ãããã¾ãã
MinGW ã¨ã MSYS 㯠SML# ã使ã£ã¦ããã°ã©ã ãæ¸ãä¸ã§ä¸»å½¹ã«ãªãããã§ã¯ãªãã®ã§èª¬æã¯çãã¾ãã
ãã SML# ã¤ã³ã¹ãã¼ã«æ¸ã¿ã ãï¼ã£ã¦æ¹ã¯å¯¾è©±ç°å¢ã使ã£ã¦ã¿ãããã©ããã
Windows 以å¤ã®æ¹ã¯ãSML#のインストール in Ch.2. SML#プログラミング環境の準備 in プログラミング言語SML#解説ãåèã«ãã¦ãã ããã
MinGW ã®ã¤ã³ã¹ãã¼ã«
ã¾ã㯠MinGW ãã¤ã³ã¹ãã¼ã«ãã¾ãããã
MinGW - Minimalist GNU for Windows | Free Development software downloads at SourceForge.net
ãã mingw-get-inst-20111118.exe (2012/4/22 ç¾å¨) ããã¦ã³ãã¼ãããã¤ã³ã¹ãã¼ã©ãå®è¡ãã¾ãã
åºæ¬çã«ã¯ã©ãã©ã次ã«é²ãã°ããã§ãããã¤ã³ã¹ãã¼ã«ããã³ã³ãã¼ãã³ããé¸ã¶é¨åã§ä¸å¿å
¨é¨ã«ãã§ãã¯ãå
¥ãã¾ããã
fortran ã¨ã ObjC ã¯ãããã«å
¥ããªãã¦ã大ä¸å¤«ã ã¨æãã¾ã(C++ãä¸è¦ã£ã½ãï¼)ã
MSYS ã®ã¤ã³ã¹ãã¼ã«
次㯠MSYS ã§ãã
MSYS | MinGW
ã®ãã¼ã¸ã®ãMSYS 1.0.11ãã¨ãããªã³ã¯ã«ç§»ãã¨ããã®ãã¡ã¤ã³ã¹ãã¼ã©ã®ãã¦ã³ãã¼ããå§ã¾ãã¾ãã
ããã¾ãã©ãã©ã次ã«é²ãã§ããã¨ãå
¥åãæ±ãããã¾ãã®ã§ã以ä¸ã®ããã«å
¥åãã¦ãã ããã
ããããããyãããyãããc:/mingwãã§ãã
MSYS DTK ã®ã¤ã³ã¹ãã¼ã«
æå¾ã¯ MSYS DTK ã§ããããã¯ãããã©ããåããã¾ããããä¸å¿ã¤ã³ã¹ãã¼ã«ãã¾ããã
MSYS | MinGW
ã®ãã¼ã¸ã®ãMSYS DTK 1.0ãã¨ãããªã³ã¯ã«ç§»ãã¨ããã¯ããã®ãã¡ã¤ã³ã¹ãã¼ã©ã®ãã¦ã³ãã¼ããå§ã¾ãã¾ãã
ãããã©ãã©ã次ã¸é²ãã§å¨è¾ºç°å¢ã®ã¤ã³ã¹ãã¼ã«ã¯å®äºã§ãã
è¨å®
ã¦ã¼ã¶ã¼ç°å¢å¤æ°ã«ã以ä¸ã®ç°å¢å¤æ°ã追å ãã¦ãã ããã
å¤æ° | å¤ |
---|---|
MINGW | C:\MinGW |
C_INCLUDE_PATH | %MINGW%\include |
CPLUS_INCLUDE_PATH | %MINGW%\include |
PATH | %MINGW%\bin |
ã¦ã¼ã¶ã¼ç°å¢å¤æ°ã«ãã§ã« PATH ãããå ´åã¯ããã®å é ã«ã%MINGW%\bin;ãã追å ãã¦ãã ããã
次ã«ãC:\MinGW\var\lib\mingw-get\data\profile.xml ãéããprofile è¦ç´ ã®åè¦ç´ ã¨ãã¦ã
<repository uri="http://www.pllab.riec.tohoku.ac.jp/smlsharp/download/mingw32/%F.xml.lzma"> <package-list catalogue="smlsharp-package-list"/> </repository>
ã追å ãã¦ãã ããã
MinGW環境にSML#を入れる際のxmlの例
ãããªæãã«ãªãã¾ãã
SML# ã®ã¤ã³ã¹ãã¼ã«
ãã¹ã¯ãããã«ãã MSYS ã®ã·ã§ã¼ãã«ãããèµ·åãã以ä¸ã®ã³ãã³ããå®è¡ãã¾ãã
ãã¹ã¯ãããã«ã·ã§ã¼ãã«ãããç¡ãå ´åãC:\msys\1.0\msys.bat ããèµ·åãã¦ãã ããã
mingw-get update mingw-get install smlsharp
ããã§ãSML# ã®ç°å¢ãæ´ãã¾ããã
SML# ã®ã¢ããã°ã¬ã¼ã
ã¨ã³ããªãæ¸ããç¿æ¥ã1.0.1 ããªãªã¼ã¹ããã¾ããã
ãã®ã¨ã³ããªã®éãã«ã¤ã³ã¹ãã¼ã«ããæ¹ã¯ã
mingw-get update mingw-get upgrade smlsharp
ã¨ããã°ææ°çã«ã¢ããã°ã¬ã¼ãã§ãã¾ãã
対話ç°å¢ã使ã£ã¦ã¿ã
ãã¦ããã§ã¯ SML# ã®å¯¾è©±ç°å¢ãèµ·åãã¦ã¿ã¾ãããã
ã¦ã£ã³ãã¦ãéãã¦ãã¾ã£ã人ã¯éãç´ãã¦ãã ããã
smlsharp
ã¨ãããã¨ã§ãSML# ã®å¯¾è©±ç°å¢ãèµ·åãã¾ãã
SML# version 1.0.0 (2012-04-06 17:51:49 JST) for x86-mingw #
ã¨è¡¨ç¤ºãããå
¥åå¾
ã¡ã«ãªãã¯ãã§ãã
試ãã«ãä½ãè¨ç®ããã¦ã¿ã¾ãã
1 + 1;
ãããå ¥åããã¨ã以ä¸ã®ãããªåºåãå¾ããã¾ãã
Creating library file: \s5cc./000.lib val it = 2 : int #
ç¾å¨ã®ãã¼ã¸ã§ã³ã® SML# 㯠C ãã©ã¤ãç´ä¸ã«ä¸æãã¡ã¤ã«ã®ç½®ãå ´ãä½ã£ã¦ãããã« .lib ãã .o ãã .s (ï¼) ãã .so ãããåºåãã¾ãã
ãã®ç½®ãå ´ã¯å®è¡æ¯ã«ç°ãªããä»åã®å ´åã¯ãs5ccãã¨ãããã©ã«ããä½ããã¾ã (1 è¡ç®ã«ãã©ã«ãåãåºåããã¦ãã)ã
対話ç°å¢ãçµäº (Ctrl+c) ããã¦ãæ¶ããªãã®ã§ãèªåã§æ¶ãããã«ãã¾ãããã
Windowsã§SML#ã®REPLãèµ·åãããã³ã«Cãã©ã¤ãç´ä¸ã«ãã©ã«ããä½ããããã®ä¸ã«libããoããsããsoãä½ããã¦ãããããæ°ãä»ããªãã¨ããããã¨ã«ãªãããã #smlsharp
@bleis ãææãããã¨ããããã¾ãï¼1.0.2çã§ã®æ¹åãæ¤è¨ãã¾ãï¼
2012-04-22 12:05:17 via web to @bleis
ã¨ã®ãã¨ãªã®ã§ãæ¹åãããããããã¾ããã
ææ°ã® 1.0.1 ã§æ¹åããã¾ãããWindows 7 ã§ã¯ã%USERPROFILE%\AppData\Local\Temp ãããã«åºåãããããã§ãã
2 è¡ç®ã¯å²ã¨ããªãã¿ã®åºåã§ããã
SML# ã§ã¯ã(F# ãªã©ã¨åæ§ã«) è©ä¾¡ããå¤ã it ã¨ããå¤æ°ã§åç
§ã§ãã¾ãã
ã¤ã¾ããå
ã»ã©ã®å
¥åã«ç¶ãã¦
it * 10;
ã¨ããã¨ã
Creating library file: \s5cc./001.lib val it = 20 : int
ã¨åºåããã次ã«ä½¿ãã it 㯠20 ã¨ãããã¨ã«ãªãã¾ãã
ã¡ãªã¿ã«ãSML# ã§ã¯ let ã§ã¯ãªã val ã使ã£ã¦å¤æ°ãå®ç¾©ãã¾ãã
val a = 10;
C è¨èªã®é¢æ°ãå¼ã³åºãã¦ã¿ã
ã§ã¯ SML# ã®ãããã¨ããã® 1 ã¤ã§ãããC è¨èªã¨ã®é£æºãã¡ãã£ã¨è¦ã¦ã¿ã¾ãããã
次ã®ããã«å
¥åãã¦ãã ããã
val print_string = _import "printf": string -> unit; print_string "hello, world!\n";
2 è¡ç®ãå®è¡ããå¾ã«ã以ä¸ã®ããã«åºåãããã¯ãã§ãã
Creating library file: \s5cc./003.lib hello, world! val it = () : unit
ãããªæãã§ãSML# ã§ã¯é常ã«ç°¡åã« C è¨èªã®é¢æ°ãå¼ã³åºããã¨ãã§ãã¾ãã
æ´ã«ã»ã»ã»
(_import "printf": (string, int) -> unit)("%d\n", 42);
ãã®ããã«å®è¡æã«ã¨ã©ã¼ããåºãªããã°ãå²ã¨èªç±ã«é¢æ°ã®åãæå®ã§ãã¾ãã
printf ã¯å¯å¤é·å¼æ°ãåãé¢æ°ãªã®ã§ã¾ãã¡ãã£ã¨éããã§ãããC è¨èªã®é¢æ°ã¨ã®å¯¾å¿ä»ãã¯å¤§ä½ä»¥ä¸ã®éãã§ãã
- C è¨èªã§ã®é¢æ°ã®ã·ã°ããã£
- Result func(Arg1 a, Arg2 b)
- SML# å´ã§ã®æå®
- (Arg1, Arg2) -> Result
ä¸ã¤æ³¨æããªããã°ãªããªãã®ã¯ãSML# ã®ã¿ãã«ã®åã¯ä¾ãã°ãa * bãã®ããã«è¡¨ãã®ã«å¯¾ãã¦ã_import ã§ã®æå®ã§ã¯ãa, bãã使ãç¹ã§ãã
ãããééã£ã¦ãã¨ã©ã¼ã«ã¯ãªãã¾ããããããããªæåã«ãªã£ããããã®ã§æ³¨æãã¦ãã ããã
ã¿ãã«
ã¿ãã«ã¯ãSML# ã§è¤æ°ã®å¤ãæ軽ã«æ±ãããã¨ãã«ä½¿ç¨ãã¾ãã
C è¨èªã¨ã®é£æºã«ããã¦ã¯ãã¿ãã«ã¯æ§é ä½ãæ±ãããã«ä½¿ãã¾ãã
ç¾å¨æå»ã®åå¾ãä¾ã«è¦ã¦ã¿ã¾ãããã
C è¨èªã§ç¾å¨æå»ãåå¾ããããã«ã¯ãtime é¢æ°ã使ããããã§ãã
/* çµæãå ¥ããtime_tå(å®ä½ã¯longå)ã®å¤t */ time_t t; /* ç¾å¨æå»ãåå¾ */ time(&t);
ããã SML# ã§æ¸ãã¦ã¿ãã¨ãããªãã¾ãã
(* 渡ãããå¼æ°ã«ç¾å¨æå»ã表ãintåã®å¤ãæ ¼ç´ããé¢æ° *) val time = _import "time": int array -> unit; (* timeã®çµæãå ¥ããå¤æ°(ãµã¤ãº1ã®é åã§ãè¦ç´ ã®å¤ã¯0) *) val res = Array.array (1, 0); (* ç¾å¨æå»ãåå¾ *) time res;
ããã§ç¾å¨æå» (ã¨ããã¯ç§) ã res ã®è¦ç´ ã¨ãã¦æ ¼ç´ãããã¨ã¯ã§ãã¾ãããããã§ã¯ãã®å¤ãä½ã表ãã¦ããã®ãç´è¦³çã§ã¯ããã¾ããã
ããã§ãC è¨èªã®ä¸çã§ã¯ãããæ§é ä½ã«å¤æãã¦æ±ã£ãããã¾ãã
/* æå»ãæ±ãã®ã«ä¾¿å©ãªæ§é ä½tm */ struct tm* t2; /* time_tãtmã«å¤æ */ t2 = localtime(&t); /* ç¾å¨æå»ãåºå */ printf("%d:%02d:%02d\n", t2->tm_hour, t2->tm_min, t2->tm_sec);
ãã®ãããªãæ§é ä½ã使ãé¢æ°ã SML# ããæ±ãããã«ã¿ãã«ã使ãã¾ãã
(* tmæ§é ä½ã¯9åã®intãæã¤(C:\MinGW\include\time.håç §)ã®ã§ã ããã表ãã¿ãã«ãtmã¨ãã¦ä½¿ããããã«ãã *) type tm = int * int * int * (* ç§ãåãæ *) int * int * int * (* æ¥ãæãå¹´ *) int * int * int; (* ææ¥ãä¸å¹´ã§ä½æ¥ç®ããå¤æé *) (* localtimeãSML#ãã使ããããã«ãã *) val localtime = _import "localtime": __attribute__((alloc)) (int array) -> tm; (* int(ã¨ããã¯ç§)ãtmã«å¤æ *) val t = localtime res; (* ç¾å¨æå»ãåºå *) val printf = _import "printf": (string, int, int, int) -> unit; printf ("%d:%02d:%02d\n", (#3 t), (#2 t), (#1 t));
ã¿ãã«ã®è¦ç´ ãåãåºãããã«ã¯ã#n é¢æ°ã使ãã¾ãã
ä»åã¯ç¾å¨æå»ãåºåãããããã¿ãã«ã® 3 çªç®ã®è¦ç´ ã2 çªç®ã®è¦ç´ ãæåã®è¦ç´ ãåãåºãããã«ã#3 é¢æ°ã#2 é¢æ°ã#1 é¢æ°ã使ãã¾ããã
å ¨ä½ãæ¸ãã¨ã
(* çµæã®å *) type tm = int * int * int * (* ç§ãåãæ *) int * int * int * (* æ¥ãæãå¹´ *) int * int * int; (* ææ¥ãä¸å¹´ã§ä½æ¥ç®ããå¤æé *) (* Cè¨èªã®é¢æ° *) val time = _import "time": int array -> unit; val localtime = _import "localtime": __attribute__((alloc)) (int array) -> tm; val printf = _import "printf": (string, int, int, int) -> unit; (* ç¾å¨æå»ãåå¾ *) val res = Array.array (1, 0); time res; (* int(ã¨ããã¯ç§)ãtmã«å¤æ *) val t = localtime res; (* ç¾å¨æå»ãåºå *) printf ("%d:%02d:%02d\n", (#3 t), (#2 t), (#1 t));
ãããªãã¾ãã
注æï¼
@dico_leque @bleis Cå´ã§ã¢ãã±ã¤ããããããªé¢æ°ãã¤ã³ãã¼ãããã¨ã誰ãããªã¼ããã¨ããåé¡ãï¼ï¼
2012-04-23 12:20:38 via twicca to @dico_leque
ã¨ã®ãã¨ãªã®ã§ã
@bleis Timeã¹ãã©ã¯ãã£è¦ããï¼localtimeçãªã®ãªãã£ãï¼æ¢ãã¦ã¿ããã©ã³ã¿ã¤ã ã§localtimeãã©ãããã¦ãã®è¦ã¤ãããï¼_import "prim_Date_localTime" : (int, int array) -> int ã§ã¤
2012-04-23 02:12:14 via Janetter to @bleis
ã®ããã«ãæ»ãå¤ã¨ãã¦ã§ã¯ãªããæå¾ã®å¼æ°ã¨ãã¦é
åã§ãã¼ã¿ãåãåãã®ãæ£ããæãï¼
ä»åã¯ãã®ããããããã®ã¯æ¬é¡ã§ã¯ãªãã®ã§æµãã¦ãã ããã
ã¬ã³ã¼ã
SML# ã§ã¯ãã¿ãã«ã¯å®ã¯ã¬ã³ã¼ãã¨ãã¦æ±ããã¨ãã§ãã¾ãããç¹å®ã®ã¬ã³ã¼ãã¯ã¿ãã«ã¨ãã¦æ±ããã¨ãã§ãã¾ãã
å
ã»ã©ã
type tm = int * int * ...
ã¨ãã¿ãã«ã®å¥åã¨ã㦠tm ãå®ç¾©ãã¾ããããå®ã¯ããæ¸ãã¾ãã
(* F#ãOCamlã¯åºåãã«;ã使ãããSML#ã§ã¯,ã使ã *) type tm = { 1: int, 2: int, 3: int, 4: int, 5: int, 6: int, 7: int, 8: int, 9: int };
ããåºåãããã¯ãã§ãã
type tm = int * int * int * int * int * int * int * int * int
ã¿ãã«ã«ãªã£ãï¼
ãã®ããã«ãSML# ã§ã¯ãã£ã¼ã«ãåå
¨ã¦ãæ°åã§æ§æãããããã 1 ããå§ã¾ãé£çªã«ãªã£ã¦ããã¨ãã¿ãã«ã¨ãã¦æ±ãããã®ã§ãã
ã¤ãã§ã«è¨ãã¨ããã£ã¼ã«ãã®ãªãã¬ã³ã¼ã㯠unit ã¨ãã¦æ±ãã¾ãã
åèªå¯¾è©±ç°å¢ã§ {}; ãå®è¡ãã¦ã¿ã¾ãããã
ã¿ãã«ã® n çªç®ã®è¦ç´ ãåãåºãããã«ãSML# ã§ã¯ #n ã使ããã¨æ¸ãã¾ããã
ããã¯å®ã¯ãã¬ã³ã¼ããããã£ã¼ã«ããåãåºãããã®é¢æ°ãªã®ã§ãã
(* ããããã¬ã³ã¼ãã®å¤aããã£ãå ´åã«... *) type t = { X: int, Y: int }; val a: t = { X = 10, Y = 20 }; (* #Xã使ã£ã¦ãã£ã¼ã«ããåãåºãã *) print (Int.toString (#X a) ^ "\n");
ã¿ãã«ã¯ãã£ã¼ã«ãåã¨ãã¦æ°åãæã£ãã¬ã³ã¼ãã¨ãã¦æ±ããã¨ãã§ããããã#n 㧠n çªç®ã®è¦ç´ ãåãåºããããã§ãã
ããã辺ã®çµ±ä¸æã¯ãªããªãã«ç´ æµã§ããã
ãã¦ãä¸ã§ã¯ type ã使ãã¾ããããå®ã¯ SML# ã§ã¯ã¬ã³ã¼ãã使ãããã« type ã¯å¿ è¦ããã¾ããã
(* SML#ã§ã¯funã«ãã£ã¦é¢æ°ãå®ç¾©ãã¾ã *) fun f { Name = n, Age = a } = (* æååã®é£çµã¯^ *) print (n ^ ":" ^ (Int.toString a) ^ "\n");
åãæ示çã«å®ç¾©ãã¦ãã¾ããããf ã«ã¯ string åã® Name ã¨ãããã£ã¼ã«ã㨠int åã® Age ã¨ãããã£ã¼ã«ããæã¤ã¬ã³ã¼ãã渡ãã¾ãã
f { Name = "hoge", Age = 42 };
æ´ã«æ´ã«ãSML# ã§ã¯å¥½ãåæã«ãã®å ´ã§ã¬ã³ã¼ããä½ãã¾ãã
(* ç¹ã«ååã¯ãªãããXã«10ãYã«20ãå ¥ã£ãã¬ã³ã¼ãã®å¤ *) val a = { X = 10, Y = 20 }; (* ç¹ã«ååã¯ãªãããXã«10ãYã«20ãZã«30ãå ¥ã£ãã¬ã³ã¼ãã®å¤ *) val b = { X = 10, Y = 20, Z = 30 }; (* ç¹ã«ååã¯ãªãããXã«10ãYã«20ãå ¥ã£ãã¬ã³ã¼ãã®å¤ *) val c = { X = 10, Y = 20 }; a = c; (* true *) a = b; (* ã³ã³ãã¤ã«ã¨ã©ã¼ *)
ã¿ãã«ä¸¦ã®æ°è»½ãã§ãåãããããååãæã£ãã¬ã³ã¼ãã使ããï¼
å¤ç¸ã¬ã³ã¼ã
ãã¦ãã¦ããã£ã¦ãã¾ããå¤ç¸ã¬ã³ã¼ãã
ã¨ãããããå¤ç¸ã¬ã³ã¼ãã£ã¦ä½ï¼ã¨ããã®ã¯ç½®ãã¨ãã¦ãå®éã«ä¾ãè¦ã¦ããã£ãã»ããåãããããã§ãããã
(* Xã¨ããååã®ãã£ã¼ã«ããæã¤ã¦ãã¨ã¼ãªã¬ã³ã¼ãã®å¤aã¨b *) val a = { X = 42, Y = 24 }; val b = { X = "hoge" }; (* ã¬ã³ã¼ãrããXã¨ãããã£ã¼ã«ãã®å¤ãåãåºãé¢æ° *) fun getX r = #X r; val x1 = getX a; val x2 = getX b;
a 㨠b 㯠X ã¨ããååã®ãã£ã¼ã«ãã¯æã£ã¦ãã¾ããããã®åãéãã¾ãã
ã«ããããããããããã®å¤ãã X ãåãåºãé¢æ°ã¨ãããã®ãæ¸ãã¦ãã¾ãã®ã§ãï¼ï¼
ãããå¤ç¸ã¬ã³ã¼ã*1ï¼ï¼ï¼
ããã ããªãããã C++ ã® template ã§ã§ãããï¼ãã¨è¨ãã¾ããã»ã»ã»
// ä¾ãã°ãããªæã #include <string> struct type_a { int x; }; struct type_b { std::string x; }; // xã¨ããã¡ã³ããããã°OK template <class T, class X> X get_x(T t) { return t.x; } int main() { type_a a = { 42 }; type_b b = { "hoge" }; int x1 = get_x<type_a, int>(a); std::string x2 = get_x<type_b, std::string>(b); }
ãªãã¨ãã® SML# ãããå¤ç¸æ§*2ãä¿ã£ãã¾ã¾åå²ã³ã³ãã¤ã«ã§ãã*3ã¨ããã®ã§ãï¼
ãã®ãããã®ä»çµã¿ã¯ã¡ããã¨ç解ãã¦ãªãã®ã§ãããæ·±ãç¥ãããæ¹ã¯
SML# - レコード多相性の理論
ãªã©ãåç
§ãã¦ãã ããã
ã¾ã¨ã
å¤ç¸ã¬ã³ã¼ããããã»ã»ã»ï¼
ãã㦠SML# ç´ æµã»ã»ã»ï¼ï¼
ãã ã¾ãè²ã
ã¨æ°ã«ãªãã¨ãããç¡ãããã§ã¯ããã¾ããã
ã§ãã§ããã
ãããã£ãæ°ã«ãªãã¨ãããéæ¹é ãã¦ãã¾ããï¼ã¨ããããã«ã½ã³ãæ§æ³ä¸ã§ãã
ãã®åããSML# ããã«ã½ã³(ä»®)ãï¼
SML# 㯠SML# ã§æ¸ããã¦ããããééã£ã¦ãªãããï¼
åèè³æ
ãã®ã¨ã³ããªãæ¸ãã«ããã£ã¦åèã«ãããã®ã§ãããããããã
Web ãã¼ã¸
人
*1:r ã®åã¯ããX ã¨ããååã®ãã£ã¼ã«ããæã£ã¦ããã¬ã³ã¼ããã¨ãªãã¾ããä»ã®ãã£ã¼ã«ããæã£ã¦ãã¦ã大ä¸å¤«ã§ãã
*2:X ã¨ããååã®ãã£ã¼ã«ãããããã°ãã¨ã¯ã©ããªåã§ãããããã¨ããæ§è³ª
*3:å¤ç¸æ§ãä¿ã£ãã¾ã¾ãªãã¸ã§ã¯ããã¡ã¤ã«ã«è½ã¡ã