Seeking for an extention (functional incapsulation)

Hello, cafe visitors! :) This is a double topic: 1. Can't find any good informative resource with descriptions of Haskell extensions. Could anybody please share good one if it exists? The only "good" one I found: http://hackage.haskell.org/trac/haskell-prime/wiki/HaskellExtensions But it's a bit too old and not that full... I undestand, that Haskell is kind of "boiling" language, in a sense of being neverending experiment. It develops all the time, extensions show up and drop out. So it's not that easy to support community with a fresh information about them. But on the other side, the property (of being "boiling" language) makes such information really important for community members... I think. :) 2. Consider situation: ----------------------------------- data SomeDataType = SomeDataType { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type} sdtField3 :: SomeDataType -> SDT_Field3Type sdtField3 sdt = f (sdtField1 sdt) (sdtField2 sdt) ----------------------------------- I induced recently, that it would be very comfortable if I could perform in a way like this: ----------------------------------- data SomeDataType = SomeDataType { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type, sdtField3 :: SDT_Field2Type, sdtField3 = f sdtField1 sdtField2} ----------------------------------- The situation is not that rare, when dealing with nonprimitive data constructions. Moreover would be really comfortable to reduce ----------------------------------- data SomeDataType = SomeDataType_111 { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type} | SomeDataType_222 { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type, sdtField5 :: SDT_Field5Type} sdtField3 :: SomeDataType -> SDT_Field3Type sdtField3 sdt = case sdt of {SomeDataType_111 -> f (sdtField1 sdt) (sdtField2 sdt) ; SomeDataType_222 -> g (sdtField1 sdt) (sdtField2 sdt) (sdtField5 sdt)} \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ data SomeDataType = SomeDataType_111 { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type, sdtField3 :: SDT_Field3Type, sdtField3 = f sdtField1 sdtField2} | SomeDataType_222 { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type, sdtField5 :: SDT_Field5Type, sdtField3 :: SDT_Field3Type, sdtField3 = g sdtField1 sdtField2 sdtField5} ----------------------------------- Usable mechanics for realization would be: 1. Funtion similar to Data.Function.on (example: (*) `on` f = \x y -> f x * f y), but opposite - I called it under. t `under` f = \x y -> (x f) `t` (y f) 2. currying and uncurrying Is there any such extension? Belka -- View this message in context: http://www.nabble.com/Seeking-for-an-extention-%28functional-incapsulation%2... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

Is there any good extension? Yes, it's in Control.Applicative. Belka wrote:
Hello, cafe visitors! :)
This is a double topic: 1. Can't find any good informative resource with descriptions of Haskell extensions. Could anybody please share good one if it exists? The only "good" one I found: http://hackage.haskell.org/trac/haskell-prime/wiki/HaskellExtensions But it's a bit too old and not that full... I undestand, that Haskell is kind of "boiling" language, in a sense of being neverending experiment. It develops all the time, extensions show up and drop out. So it's not that easy to support community with a fresh information about them. But on the other side, the property (of being "boiling" language) makes such information really important for community members... I think. :)
2. Consider situation: ----------------------------------- data SomeDataType = SomeDataType { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type} sdtField3 :: SomeDataType -> SDT_Field3Type sdtField3 sdt = f (sdtField1 sdt) (sdtField2 sdt) ----------------------------------- I induced recently, that it would be very comfortable if I could perform in a way like this: ----------------------------------- data SomeDataType = SomeDataType { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type, sdtField3 :: SDT_Field2Type, sdtField3 = f sdtField1 sdtField2} ----------------------------------- The situation is not that rare, when dealing with nonprimitive data constructions. Moreover would be really comfortable to reduce ----------------------------------- data SomeDataType = SomeDataType_111 { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type} | SomeDataType_222 { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type, sdtField5 :: SDT_Field5Type}
sdtField3 :: SomeDataType -> SDT_Field3Type sdtField3 sdt = case sdt of {SomeDataType_111 -> f (sdtField1 sdt) (sdtField2 sdt) ; SomeDataType_222 -> g (sdtField1 sdt) (sdtField2 sdt) (sdtField5 sdt)}
\/ \/ \/ \/ \/ \/ \/ \/ \/ \/
data SomeDataType = SomeDataType_111 { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type, sdtField3 :: SDT_Field3Type, sdtField3 = f sdtField1 sdtField2} | SomeDataType_222 { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type, sdtField5 :: SDT_Field5Type, sdtField3 :: SDT_Field3Type, sdtField3 = g sdtField1 sdtField2 sdtField5} -----------------------------------
Usable mechanics for realization would be: 1. Funtion similar to Data.Function.on (example: (*) `on` f = \x y -> f x * f y), but opposite - I called it under. t `under` f = \x y -> (x f) `t` (y f) 2. currying and uncurrying
Is there any such extension?
Belka

More specifically: sdtField3 sdt = f <$> sdtField1 <*> sdtField2 You don't really need this inline in the record syntax, do you? Dan Weston wrote:
Is there any good extension? Yes, it's in Control.Applicative.
Belka wrote:
Hello, cafe visitors! :)
This is a double topic: 1. Can't find any good informative resource with descriptions of Haskell extensions. Could anybody please share good one if it exists? The only "good" one I found: http://hackage.haskell.org/trac/haskell-prime/wiki/HaskellExtensions But it's a bit too old and not that full... I undestand, that Haskell is kind of "boiling" language, in a sense of being neverending experiment. It develops all the time, extensions show up and drop out. So it's not that easy to support community with a fresh information about them. But on the other side, the property (of being "boiling" language) makes such information really important for community members... I think. :)
2. Consider situation: ----------------------------------- data SomeDataType = SomeDataType { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type} sdtField3 :: SomeDataType -> SDT_Field3Type sdtField3 sdt = f (sdtField1 sdt) (sdtField2 sdt) ----------------------------------- I induced recently, that it would be very comfortable if I could perform in a way like this: ----------------------------------- data SomeDataType = SomeDataType { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type, sdtField3 :: SDT_Field2Type, sdtField3 = f sdtField1 sdtField2} ----------------------------------- The situation is not that rare, when dealing with nonprimitive data constructions. Moreover would be really comfortable to reduce ----------------------------------- data SomeDataType = SomeDataType_111 { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type} | SomeDataType_222 { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type, sdtField5 :: SDT_Field5Type}
sdtField3 :: SomeDataType -> SDT_Field3Type sdtField3 sdt = case sdt of {SomeDataType_111 -> f (sdtField1 sdt) (sdtField2 sdt) ; SomeDataType_222 -> g (sdtField1 sdt) (sdtField2 sdt) (sdtField5 sdt)}
\/ \/ \/ \/ \/ \/ \/ \/ \/ \/
data SomeDataType = SomeDataType_111 { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type, sdtField3 :: SDT_Field3Type, sdtField3 = f sdtField1 sdtField2} | SomeDataType_222 { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type, sdtField5 :: SDT_Field5Type, sdtField3 :: SDT_Field3Type, sdtField3 = g sdtField1 sdtField2 sdtField5} -----------------------------------
Usable mechanics for realization would be: 1. Funtion similar to Data.Function.on (example: (*) `on` f = \x y -> f x * f y), but opposite - I called it under. t `under` f = \x y -> (x f) `t` (y f) 2. currying and uncurrying
Is there any such extension?
Belka

You don't really need this inline in the record syntax, do you? In fact, that was the point. To enclose direct functional dependants into
sdtField3 sdt = f <$> sdtField1 <*> sdtField2 Doesn't look much better than my "under" function (t `under` f = \x y -> (x f) `t` (y f)). What did I miss? I believe, there are good reasons to use Control.Applicative for lots
Thank you, for your reply, Dan! :) the record declaration. To achieve better pithiness - it's valuable, and the value grows exponentially with LOC (lines of code) count. :) purposes, but unfortunately, yet haven't had time to try it in my practice. Belka -- View this message in context: http://www.nabble.com/Seeking-for-an-extention-%28functional-incapsulation%2... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

the value grows exponentially with LOC (lines of code) count. :)
Exponentially? Now I'm missing something... Your way has 156 chars: data SomeDataType = SomeDataType { sdtField1 :: SDT_Field1Type, sdtField2 ::
SDT_Field2Type, sdtField3 :: SDT_Field2Type, sdtField3 = f sdtField1 sdtField2}
This way has 162 chars: data SomeDataType = SomeDataType { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type} sdtField3 :: SDT_Field2Type sdtField3 = f <$> sdtField1 <*> sdtField2 This adds 6 characters per dependent deconstructor function. As a fraction of total LOC, this is insignificant. Belka wrote:
Thank you, for your reply, Dan! :)
You don't really need this inline in the record syntax, do you? In fact, that was the point. To enclose direct functional dependants into the record declaration. To achieve better pithiness - it's valuable, and the value grows exponentially with LOC (lines of code) count. :)
sdtField3 sdt = f <$> sdtField1 <*> sdtField2 Doesn't look much better than my "under" function (t `under` f = \x y -> (x f) `t` (y f)). What did I miss? I believe, there are good reasons to use Control.Applicative for lots purposes, but unfortunately, yet haven't had time to try it in my practice.
Belka

Exponentially? Now I'm missing something... I meant: in as-is version you have 3 declarations (data, sdtField2 :: ..., sdtField2 = ...), but in a proposed one - only one, with subdeclarations. My
perception is more oriented on that compositional criterion, than calculates char counts. Besides, syntactically proposed version sticks together entities that are very closely related. -- View this message in context: http://www.nabble.com/Seeking-for-an-extention-%28functional-incapsulation%2... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

Belka wrote:
Exponentially? Now I'm missing something... I meant: in as-is version you have 3 declarations (data, sdtField2 :: ..., sdtField2 = ...), but in a proposed one - only one, with subdeclarations. My perception is more oriented on that compositional criterion, than calculates char counts. Besides, syntactically proposed version sticks together entities that are very closely related.
I guess, I was too fast calling it (growth of code units with LOC in as-is version against proposed one) exponential. :) It is not. Proportional. But that's not that important. -- View this message in context: http://www.nabble.com/Seeking-for-an-extention-%28functional-incapsulation%2... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
participants (2)
-
Belka
-
Dan Weston