I am trying to implement a Haskell counterpart of the View
protocol of SwiftUI using type class and type family.
The View
protocol in SwiftUI is something like:
protocol View {
associatedtype Body: View
var body: Body { get }
}
Through type class and the associated type family, I can have:
{-# LANGUAGE TypeFamilies, AllowAmbiguousTypes, FlexibleContexts, U
ndecidableSuperClasses #-}
class (View (Body x)) => View x where
type Body x
body :: Body x
which fails to compile: solveWanteds: too many iterations (limit = 4)
.
My question is if there is a way to achieve such ‘recursive’ type class definition in Haskell?