BinRoot
BinRoot

Reputation: 694

How to create a data type with value constructor containing list of type parameter types

I have a data structure with a type parameter called Fluent. I want a list of these. What's the most elegant way to fix this code?

data Fluent t = Fluent [t]
data Obj = Obj [Fluent]

Edit: I want to be able to do this:

f1 = Fluent [True, False]
f2 = Fluent [1, 2, 3, 4]
let o = Obj [f1, f2]

Upvotes: 0

Views: 56

Answers (1)

amalloy
amalloy

Reputation: 91857

You have to propagate the type parameter t up to the Obj type:

data Fluent t = Fluent [t]
data Obj t = Obj [Fluent t]

:t Obj $ map Fluent ["a", "bcd"] -- Obj Char

Upvotes: 3

Related Questions