[Haskell-cafe] Existencial Types

Ryan Ingram ryani.spam at gmail.com
Tue Dec 1 19:43:13 EST 2009


newtype Transformation = Transformation {
    (<+>) :: SPLModel -> InstanceModel -> InstanceModel
  }

data SelectScenarios = SelectScenarios { scIds :: [Id] }

scenarioTransform scenario = Transformation $ \spl inst -> something

testScenario = SelectScenarios []
test = scenarioTransform testScenario <+> undefined

Don't use typeclasses unless you really need to.  Higher-order
functions are usually what you want.

  -- ryan

On Tue, Dec 1, 2009 at 3:21 PM, rodrigo.bonifacio
<rodrigo.bonifacio at uol.com.br> wrote:
> Thanks Luke.
>
> In fact I, will have different implementations of the Transformation type.
> Something like:
>
> data SelectScenarios = SelectScenarios {
>
> scIds :: [Id]
>
> }
>
>
>
> And then I should be able to make SelectScenarios a kind of Transformation.
> So I think that I really need a class. What do you think about it?
>
> instance Transformation SelectScenario where
>
> (<+>)  ....
>
>
>
> Regards,
>
> Rodrigo.
>
>
>
>
>
>
>
>
>
>
>
> Em 01/12/2009 19:39, Luke Palmer < lrpalmer at gmail.com > escreveu:
>
> On Tue, Dec 1, 2009 at 11:21 AM, David Menendez wrote:
>> On Tue, Dec 1, 2009 at 1:00 PM, rodrigo.bonifacio
>> wrote:
>>> Dear all, I wrote the following  types:
>>>
>>>> class Transformation t where
>>>>  (<+>) :: t -> SPLModel  -> InstanceModel -> InstanceModel
>>>
>>>> data Configuration = forall t . Transformation t => Configuration
>>>> (FeatureExpression, [t])
>>>> type ConfigurationKnowledge = [Configuration]
>
> I would suggest doing away with the class in a case like this.
>
> data Transformation = Transformation {
> (<+>) :: SPLModel -> InstanceModel -> InstanceModel
> }
>
> data Configuration = Configuration FeatureExpression [Transformation]
>
> I suspect that it was OO heritage that l ed you to want a class here?
> Forget that! :-)
>
> Luke
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>


More information about the Haskell-Cafe mailing list