class Hoge { public static <A> A foo(A x) { if (x instanceof String) return null; return x; } public static void main(String[] args) { System.out.println(foo("Hello")); // -| null System.out.println(foo(42)); // -| 42 System.out.println(foo(new Object())); // -| java.lang.Object@15db9742 } } ãã®ä¾ã«ã¤ãã¦ã¯ãéçåããäºæ³ãããæåãè£åããããªããã°ã©ã ãæ¸ããã ãã§ä½ãå¬ãããªãããã©ãæã«ã¯å®è¡æåæ å ±ã便å©ãªå ´åãããã åã表ãå¤ ä¸ã®ä¸ã«ã¯å®è¡æåæ å ±ã®ããã¸ã§ããªã¯ã¹ããçã®ã¸ã§ããªã¯ã¹
I've just come across the following code snippet in OCaml's documentation about GADTs: let rec eval : type a. a term -> a = function | Int n -> n | Add -> (fun x y -> x + y) | App (f, x) -> (eval f) (eval x) which, once evaluated in utop, has the following signature: val eval : 'a term -> 'a = <fun> I also noticed that, when replacing type a. a term -> a by 'a term -> 'a or just removing the signa
ãã®ã¨ã³ããªã¯ML Advent Calendar 2015ã®14æ¥ç®ã®è¨äºã§ãã 13æ¥ç®ã®è¨äºã¯ãããããã®é¢æ°åããã°ã©ãã³ã°ã«ãããå帰é¢æ°ã®èãæ¹ã§ããã ML Advent Calendar 2015ã追ã£ã¦ããæ¹ãªã大ä½å¯ããä»ãã¨æãã¾ããããã®è¨äºã¯obj_magicããã® A GADT implementation of AVL treeã«åºæ¿ãåãã¦æ¸ãã¾ããã GADTã¨åã¬ãã«èªç¶æ°ã使ã£ã¦AVLæ¨ãæ¸ããã®ãªããä»ã®ãã¼ã¿æ§é ãåãããªã§å®è£ ãã¦ã¿ãã¨é¢ç½ããã ã¨æã£ãã®ã§â¦ã¾ãäºçªç ãã§ããã äºé ãã¼ãã¨ã¯ ãã¼ã¸ãéããã¼ãã®å®è£ ã®ä¸ç¨®ãããã§ããåãäºé ãã¼ããå®è£ ããã®ã¯ãããåãã¦ã§è©³ããäºã¯åãããªãã®ã§ãæ°ã«ãªã£ãæ¹ã¯ Amazon.co.jpï¼ Purely Functional Data Structures: Chris Okasaki:
Not your computer? Use a private browsing window to sign in. Learn more about using Guest mode
Iâve been interested in GADTs1 for quite some time now but Iâve had a hard time finding proper use-cases for them in my day-to-day programming tasks; this is not because GADTs arenât useful, they are, but rather that my understanding of them has been limited. I often experience this when Iâm learning more advanced features of programming languages and Iâve found that I personally find it easier to
When GADTs (Generalized Algebraic Data Types) landed in OCaml, I wasnât particularly happy about it. I assumed that it was the kind of nonsense you get when you let compiler writers design your programming language. Which is to say that the standard GADT examples all seem to be about the kinds of things that compiler writers do, like embed domain-specific languages or build typed abstract-syntax t
ä»åã¯OCamlã®ç¾å¨ã®latest versionã§ãã3.12.1ã«ã¯å®è£ ããã¦ããªããGADTã«ã¤ãã¦è©¦ãã¦ã¿ã¾ããã ã¨ãããããç¾ç¶ã§OCamlã®GADTã試ãã«ã¯OCamlã®svnãªãã¸ããªããgadtsãã¨ã£ã¦ãã¦ãã«ãã¨ã¤ã³ã¹ãã¼ã«ãè¡ãå¿ è¦ãããã¾ãã ãã ãããããè¡ãã¨ãä»ã¾ã§å ¥ãã¦ããæ¨æºã§ãªãã©ã¤ãã©ãªã®ãã¡ãcmiãã¡ã¤ã«ãé¢ä¿ããã©ã¤ãã©ãªã¯ã»ã¼å ¨æ» ãã¾ãï¼å¤åï¼ãã¤ã¾ãèªåã§å ¥ãç´ãã§ããããã«ãã¼ã¸ã§ã³åãå¤æ´ããããããé¢ä¿ã§oasisããã±ã¼ã¸ã§OCamlã®ãã¼ã¸ã§ã³æå®ãããå ´åããã®ã¾ã¾ã§ã¯å¯¾å¿ãã¦ããªããã¼ã¸ã§ã³ã¨ãã¦æ±ããããªã©ã®åé¡ãããã¾ããç¾ç¶ããã®ã¾ã¾æ®æ®µã®éçºã§ä½¿ãã«ã¯ããªãèªåã§ã®è§£æ±ºãå¿ è¦ã«ãªãããã§ãã ããã§ã¯ä»¥ä¸ã®ãã¨ã«æ³¨æããªãããGADT対å¿ãã¼ã¸ã§ã³ãå ¥ãã¦ã¿ã¾ãã $ svn co http://caml.inria
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}