我正在尝试创建一个函数,该函数接受对象justifyList列表( ) 并返回所有类型对象的列表,并丢弃参数列表中的任何元素。Maybe[Maybe a]JustNothing
我现在的解决方案是
justifyList :: [Maybe a] -> [a]
justifyList [] = []
justifyList (x:xs)
| (isNothing x) = justifyList xs
| otherwise = x : justifyList xs
Run Code Online (Sandbox Code Playgroud)
我尝试递归地迭代参数列表,并将当前元素递归地放入x返回的 list 中[a](如果它是Just类型的话)。
但是,在解释时会生成类型不匹配错误
无法将类型 a 与 Maybe a 匹配
因此我的问题是;如何递归地遍历对象列表Maybe?如果这个解决方案足够了,我如何转换xs为Maybe类型?
我有一个带有工作 GUI 的 Windows 窗体应用程序。但是,我希望该应用程序能够在命令行界面以及常规 GUI 应用程序中启动和使用。当应用程序在 CLI 中启动时,不应使用 GUI,而是将相关信息写入 CLI 应用程序。我需要做的是一种检测应用程序(其 exe 文件)是在 CLI 应用程序(例如常规 windows CMD)中启动还是以正常方式启动(例如单击文件资源管理器中的 exe 文件或使用)的方法桌面快捷方式。
最好在应用程序的主要方法中进行检测,例如
static class Program
{
[STAThread]
static void Main()
{
//if(application not started in a CLI-application)
Application.Run(new DriverToolApplicationContext());
//else
//Console.writeLine("Application started in CLI-application");
}
}
Run Code Online (Sandbox Code Playgroud)
如何最好地实施这种检测?我最好不想在 main 方法中放置任何参数。