Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
pp:class [2021/04/11 14:43]
lfa
pp:class [2021/04/11 22:15] (current)
lfa
Line 26: Line 26:
  
 Now let's check one more interesting concept, Haskell'​s class system. Now let's check one more interesting concept, Haskell'​s class system.
-If //data// can be considered the //class// from Java, then ''​class''​ could be considered the //​interface//​ from Java. 
  
 If you're defining a new //data Point//, you probably encountered some problems trying to print it in GHCI. If you're defining a new //data Point//, you probably encountered some problems trying to print it in GHCI.
Line 87: Line 86:
 As you can see, now we can add our data types in the new class, but also Haskell'​s types. The only requirement is that the enrolled type must implement our method. As you can see, now we can add our data types in the new class, but also Haskell'​s types. The only requirement is that the enrolled type must implement our method.
  
-5. Create a class ''​Contains b a''​ that will require a ''​contains :: b -> a -> Bool''​ method which will return True if ''​a''​ is in ''​b''​.+5. Create a class ''​Contains b a''​ that will require a ''​contains :: b -> a -> Bool''​ method which will return True if ''​a''​ is in ''​b''​. Add ''​[a]'',​ ''​List a''​ and ''​BTree a''​ to this class.
 <note tip>Do we need any additional restrictions for a or b? You can still add restrictions:​ <note tip>Do we need any additional restrictions for a or b? You can still add restrictions:​
 <code haskell> <code haskell>
Line 93: Line 92:
 </​code></​note>​ </​code></​note>​
  
-6. Create the ''​class Size a''​ which will require the methods ''​size''​ and ''​uniqueSize''​+6. Create the ''​class Size a''​ which will require the methods ''​size''​ and ''​uniqueSize''​. Add ''​[a]'',​ ''​List a''​ and ''​BTree a''​ to this class.
      - //size// = the numbers of elements in **a**      - //size// = the numbers of elements in **a**
      - //​uniqueSize//​ = the number of uniqueElements in **a**      - //​uniqueSize//​ = the number of uniqueElements in **a**