KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I expected the following code to fail with a type error due to violation of the minBound and maxBound. But, as you can see, it goes through without flagging an error. {-# OPTIONS_GHC -XTypeSynonymInstances #-} module Main where type Probability = Float instance Bounded Probability where minBound = 0.0 maxBound = 1.0 testout :: Float -> Probability testout xx = xx + 1.0 main = do putStrLn $ show $ testout 0.5 putStrLn $ show $ testout (-1.5) putStrLn $ show $ testout 1.5 In the Prelude I get this *Main> :type (testout 0.5) (testout 0.5) :: Probability And at the prompt I get this: [~/test]$runhaskell demo.hs 1.5 -0.5 2.5 Clearly I'm not declaring Bounded properly, and I'm sure I'm doing something wrong syntactically. There isn't much simple stuff on Google regarding Bounded typeclasses, so any help would be much appreciated.
Tags (comma-separated)
Save Edits
Cancel