Skip to content

Commit

Permalink
Add unit testing of fapply|fapplyLam|bind|join for FreeMonad(F, A)
Browse files Browse the repository at this point in the history
* Fix some errors in the functions fapply, fapplyLam, bind and join.
  • Loading branch information
flyfish30 committed Oct 11, 2024
1 parent cdf7e45 commit af5eaf3
Show file tree
Hide file tree
Showing 2 changed files with 303 additions and 31 deletions.
9 changes: 6 additions & 3 deletions src/base.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ pub fn GetPointerChild(comptime P: type) type {
}

pub fn MapFnInType(comptime MapFn: type) type {
const len = @typeInfo(MapFn).Fn.params.len;
const _MapFn = if (@typeInfo(MapFn) == .Pointer) std.meta.Child(MapFn) else MapFn;
const info = @typeInfo(_MapFn);
const len = info.Fn.params.len;

if (len != 1) {
@compileError("The map function must has only one parameter!");
}

return @typeInfo(MapFn).Fn.params[0].type.?;
return info.Fn.params[0].type.?;
}

pub fn MapFnRetType(comptime MapFn: type) type {
const R = @typeInfo(MapFn).Fn.return_type.?;
const _MapFn = if (@typeInfo(MapFn) == .Pointer) std.meta.Child(MapFn) else MapFn;
const R = @typeInfo(_MapFn).Fn.return_type.?;

if (R == noreturn) {
@compileError("The return type of map function must not be noreturn!");
Expand Down
Loading

0 comments on commit af5eaf3

Please sign in to comment.