w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Trying to develop a recursive type-level function to derive function input and output

I would start with a single-parameter type class with two associated type families for TransIn and TransOut.

class Transform t where
  type TransIn t
  type TransOut t
  trans :: t -> TransIn t -> TransOut t

Now you need six instances for the six equations for TypeIn and TypeOut. Here is the first one.

instance Transform (R PA (S a)) where
  type TransIn (R PA (S a)) = a
  type TransOut (R PA (S a)) = Box (R PA (S a)) a
  trans t a = error "implement me!"

Note that the definitions for TransIn and TransOut are literally the equations from the question.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.