Guest User

Untitled

a guest
May 23rd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. type Polygon =
  2. struct
  3. val Coords : list
  4. new(list_of_Coords) = { Coords = list_of_Coords }
  5. end
  6.  
  7. type Polygon =
  8. struct
  9. val Coords : list<float>
  10. new(list_of_Coords) = { Coords = list_of_Coords }
  11. end
  12.  
  13. type 'a Polygon =
  14. struct
  15. val Coords : 'a list
  16. new(list_of_Coords) = { Coords = list_of_Coords }
  17. end
  18.  
  19. type Polygon = { Coords : Coord list }
  20.  
  21. // Code ...
  22.  
  23. let myPolygon = { Coords = [ ... ] }
  24.  
  25. type Polygon<'a> =
  26. struct
  27. val Coords : list <'a>
  28. new(list_of_Coords) = { Coords = list_of_Coords }
  29. end
  30.  
  31. let inline genPolygon (a: 'a list) =
  32. new Polygon<'a> (a)
  33.  
  34. > genPolygon [1;2;3];;
  35. val it : Polygon<int> = FSI_0002+Polygon`1[System.Int32] {Coords = [1; 2; 3];}
  36. > genPolygon [1.0;2.0;3.0];;
  37. val it : Polygon<float>
  38. = FSI_0002+Polygon`1[System.Double] {Coords = [1.0; 2.0; 3.0];}
  39.  
  40. type 'a F =
  41. {coords: 'a list;}
  42.  
  43. > let dd = {coords=[1.;2.]};;
  44.  
  45. val dd : float F
  46.  
  47. > let dd = {coords=[[1.;2.];[1.;2.]]};;
  48.  
  49. val dd : float list F
  50.  
  51. type Coord =
  52. struct
  53. val X : float
  54. val Y : float
  55. new(x,y) = { X = x ; Y = y }
  56. end
  57.  
  58. type DepthCurve =
  59. struct
  60. val Coords : list<Coord>
  61. val Depth : float
  62. new(list_of_Coords, depth) = { Coords = list_of_Coords ; Depth = depth}
  63. end
  64.  
  65. let myCoord1 = new Coord(1.,2.)
  66. let myCoord2 = new Coord(3.,4.)
  67. let myDepthCurve = new DepthCurve([myCoord1;myCoord2] , 5. )
  68.  
  69. type Coord = { X : float; Y : float }
  70. type 'a DepthCurve = {coords: 'a list;}
  71. let myDepthCurve = {coords=[[1.;2.];[3.;4.]]};;
  72.  
  73. type 'a DepthCurve = {coords: 'a list; depth: float}
  74. let myDepthCurve = {coords=[[1.;2.];[3.;4.]] , 5. };;
  75.  
  76. type Coord = { X : float; Y : float }
  77. type DepthCurve<'a> =
  78. struct
  79. val Coords : list <'a>
  80. new(list_of_Coords) = { Coords = list_of_Coords }
  81. end
  82.  
  83. let inline genDepthCurve (a: 'a list) =
  84. new DepthCurve<'a> (a)
  85.  
  86. let myDepthCurve = genDepthCurve [1;2;3];;
Add Comment
Please, Sign In to add comment