[Haskell-cafe] Constructors on left and right hand sides of equation
PATRICK BROWNE
patrick.browne at dit.ie
Wed Sep 17 14:03:41 UTC 2014
Dear list
In Eq 1 is (NewGlass i) on the LHS distinct from (NewGlass i) on the RHS?
In Eq2 are the occurrences of the data constructor Fill on the LHS and
RHS distinct?
Thanks
Pat
data Glass = NewGlass Int | Fill Glass Int deriving Show
drink :: Glass -> Int -> Glass
drink (NewGlass i) j = (NewGlass i) -- Eq 1
drink (Fill m i) j
| full (Fill m i) = Fill (NewGlass (size m)) ((size m) -
j) -- Eq 2
| (i >= j) = Fill m (i-j)
| otherwise = drink m (j-1)
size :: Glass -> Int
size (NewGlass i) = i
size (Fill m i) = size m
level :: Glass -> Int
level (NewGlass i) = 0
level (Fill m i)
| (level m) + i > (size m) = size m
| otherwise = (level m) + i
empty :: Glass -> Bool
empty m = (level m) == 0
full :: Glass -> Bool
full m = (level m) == (size m)
{-
drink (Fill (NewGlass 4) 5) 5
drink (Fill (NewGlass 4) 3) 3
-}
--
This email originated from DIT. If you received this email in error, please
delete it from your system. Please note that if you are not the named
addressee, disclosing, copying, distributing or taking any action based on
the contents of this email or attachments is prohibited. www.dit.ie
Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí
earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an
seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon
dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa
ríomhphost nó sna hiatáin seo. www.dit.ie
Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to
Grangegorman <http://www.dit.ie/grangegorman>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140917/18d41fc5/attachment.html>
More information about the Haskell-Cafe
mailing list