Hack Forums
What is the Haskell equivalent to struct in C? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Coders Lounge (https://hackforums.net/forumdisplay.php?fid=5)
+---- Thread: What is the Haskell equivalent to struct in C? (/showthread.php?tid=5248832)



What is the Haskell equivalent to struct in C? - cortland12 - Apr 25, 2016

Question in thread title. If I worded that properly. My initial thought was:

PHP Code

<?php 
data Fish 
= Name | Species |Teeth | Age 

PHP Code

<?php 
struct fish 
{ 
  const 
char *name; 
  const 
char *species; 
  
int teeth;
  
int age; 
} 

but I'm not totally sure. Any assistance?


* - bbbysmth - Apr 25, 2016

You are probably looking for a record data structure.


* - cortland12 - Apr 25, 2016

Found out it is similar to the product type in Haskell

Here it is...

PHP Code

<?php 
data Fish 
= Fish { 
  
name :: String, 
  
species :: String, 
  
teeth :: Int, 
  
age :: Int 
}