Keith Sheppard keithshep at gmail.com
Tue Dec 22 09:27:47 EST 2009

```Hello, I didn't try to understand what the function is doing, but just
quickly noticed that

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

can be written as
> reMatr a = Matr . ((flip (.) unMatr) a)

but that
> reMatr = Matr . (flip (.) unMatr)

can be written as
> reMatr a = (Matr . (flip (.) unMatr)) a

so because of precedence rules a different function is being applied
to 'a' in the 2 versions

Best
Keith

On Tue, Dec 22, 2009 at 9:13 AM, slemi <0slemi0 at gmail.com> 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-tp26881661p26888978.html
> Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
>
> _______________________________________________