slemi 0slemi0 at gmail.com
Wed Dec 23 08:40:46 EST 2009

```i dont know any calculus-thingy, this is what i did:

reMatr a = Matr . a . unMatr
reMatr a = Matr . (. unMatr) a
reMatr a = Matr . (flip (.) unMatr) a
reMatr = Matr . (flip (.) unMatr)

as  http://old.nabble.com/pointfree-trouble-td26881661.html#a26889388 Daniel
pointed out, this doesnt work because (flip (.) unMatr) takes two arguments.
i'm really interested in this calculus stuff, looking up now:)

Kim-Ee Yeoh wrote:
>
> There you have it: fully- and semi-pointfree versions of reMatr.
>
> A heads up: aggressively pursuing pointfreeness without type signatures
> guarantees a courtesy call from the monomorphism restriction,
>
> As for your question on why the original code doesn't typecheck: if
> you explain how you arrived at it, perhaps we can figure out where
> you tripped up. Daniel Fischer for instance, *calculated* for you
> the right answer. Habeas calculus and all that.
>
>
> slemi wrote:
>>
>> thanks, that's a really neat syntactic sugar :)
>>
>> however, my original question was how to make the reMatr function
>> pointfree, as
>> reMatr = Matr . (flip (.) unMatr)
>> is not working. any ideas/explanation why it doesnt work?
>>
>>
>> Kim-Ee Yeoh wrote:
>>>
>>> Here's another way of writing it:
>>>
>>> data Matrix a = Matr {unMatr :: [[a]]} | Scalar a  deriving (Show, Eq)
>>> -- RealFrac constraint removed
>>>
>>> reMatr :: RealFrac a => ([[a]] -> [[a]]) -> (Matrix a -> Matrix a)
>>> reMatr f = Matr . f . unMatr     -- this idiom occurs a lot, esp. with
>>> newtypes
>>>
>>> Affixing constraints to type constructors is typically deprecated.
>>>
>>>
>>>
>>> slemi wrote:
>>>>
>>>> i have trouble making a function pointfree:
>>>>
>>>> data RealFrac a => Matrix a = Matr [[a]] | Scalar a
>>>>   deriving (Show, Eq)
>>>>
>>>> unMatr :: RealFrac a => Matrix a -> [[a]]
>>>> unMatr = (\(Matr a) -> a)
>>>>
>>>> reMatr :: RealFrac a => ([[a]] -> [[a]]) -> (Matrix a -> Matrix a)
>>>> reMatr a = Matr . (flip (.) unMatr) a
>>>>
>>>> this works fine, but if i leave the 'a' in the last function's
>>>> definition like this:
>>>> reMatr = Matr . (flip (.) unMatr)
>>>> it gives an error. can anybody tell me why? (i'm using ghci)
>>>>
>>>
>>>
>>
>>
>
>

--
View this message in context: http://old.nabble.com/pointfree-trouble-tp26881661p26902326.html