[Haskell-cafe] Set of reals...?

Keean Schupke k.schupke at imperial.ac.uk
Thu Oct 28 05:16:35 EDT 2004


erm, yes you're right - don't know why that is - seems a fairly
arbitrary decision to me... perhaps someone else knows a good
reason why normal function definiton is not allowed?

Stijn De Saeger wrote:

>aha, I see. 
>Seems like i still have a long way to go with functional programming. 
>
>final question: i tried to test the code below, but it seems GHCi will
>only take the `isin` functions when they are defined in lambda
>notation (like isin = (\x -> ...)).
>Did you run this code too, or were you just sketching me the rough idea? 
>
>Cheers for all the replies by the way, i learnt a great deal here.
>stijn.
>
>
>On Wed, 27 Oct 2004 14:09:36 +0100, Keean Schupke
><k.schupke at imperial.ac.uk> wrote:
>  
>
>>Well, its functional of course:
>>
>>    union :: Interval -> Interval -> Interval
>>    union i j = Interval {
>>       isin x = isin i x || isin j x
>>    }
>>
>>    intersection :: Interval -> Interval -> Interval
>>    intersection i j = Interval {
>>       isin x = isin i x && isin j x
>>    }
>>
>>    Keean.
>>
>>
>>
>>
>>Stijn De Saeger wrote:
>>
>>    
>>
>>>That seems like a very clean way to define the sets indeed, but how
>>>would you go about implementing operations like intersection,
>>>complement etc... on those structures? define some sort of algebra
>>>over the functions? or extend such sets by adding elements? hm...
>>>sounds interesting,.
>>>
>>>thanks,
>>>stijn.
>>>
>>>
>>>On Wed, 27 Oct 2004 11:52:54 +0100, Keean Schupke
>>><k.schupke at imperial.ac.uk> wrote:
>>>
>>>
>>>      
>>>
>>>>I think someone else mentioned using functions earlier,
>>>>rather than a datatype why not define:
>>>>
>>>>   data Interval = Interval { isin :: Float -> Bool }
>>>>
>>>>Then each range becomes a function definition, for example:
>>>>
>>>>   myInterval = Interval {
>>>>      isin r
>>>>         | r == 0.6 = True
>>>>         | r > 0.7 && r < 1.0 = True
>>>>         | otherwise = False
>>>>      }
>>>>
>>>>Then you can test with:
>>>>
>>>>   (isin myInterval 0.6)
>>>>
>>>>Keean
>>>>
>>>>
>>>>
>>>>
>>>>        
>>>>
>>    
>>



More information about the Haskell-Cafe mailing list