This can be achieved by introducing a new VehicleType data VehicleType and adding another parameter to Vehicle as follows:
data VehicleType = BicycleT | CarT | BusT data Vehicle : PowerSource -> VehicleType -> Type where Bicycle : Vehicle Pedal BicycleT Car : (fuel : Nat) -> Vehicle Petrol CarT Bus : (fuel : Nat) -> Vehicle Petrol BusT
You must somehow encode the type difference between the constructors. If you need extra type safety, you need to add extra type information. Then you can use it to implement the refuel function:
refuel : Vehicle Petrol t -> Nat -> Vehicle Petrol t refuel (Car fuel) x = Car (fuel + x) refuel (Bus fuel) x = Bus (fuel + x)
Replacement
refuel (Car fuel) x = Car (fuel + x)
with
refuel (Car fuel) x = Bus (fuel + x)
results in an error of the following type:
Type checking ./Fuel.idr Fuel.idr:14:8:When checking right hand side of refuel with expected type Vehicle Petrol CarT Type mismatch between Vehicle Petrol BusT (Type of Bus fuel) and Vehicle Petrol CarT (Expected type) Specifically: Type mismatch between BusT and CarT
source share