小编tre*_*ore的帖子

我必须实现Applicative和Functor来实现Monad

我正在尝试实现Monad实例.作为一个更简单的示例,假设以下内容:

data Maybee a = Notheeng | Juust a 

instance Monad Maybee where
   return x = Juust x
   Notheeng >>= f = Notheeng
   Juust x >>= f = f x
   fail _ = Notheeng 
Run Code Online (Sandbox Code Playgroud)

据我所知,这应该是Maybe的标准实现.但是,这不会编译,因为编译器抱怨:

没有实例(Applicative Maybee)

同样,一旦给出Applicative,他就想要一个Functor实例.

所以:简单的问题:在我实现Monad之前,我是否必须始终实现Functor和Applicative?

monads haskell functor applicative fam-proposal

7
推荐指数
3
解决办法
680
查看次数

Robolectric:窗口创建失败

我正在尝试使用robolectric来避免为每次测试运行启动仿真器.我按照这个(非常好的)教程设置了所有内容:http://www.peterfriese.de/unit-testing-android-apps-with-robolectric-and-eclipse/ 不幸的是我收到一个错误:

java.lang.RuntimeException: Window creation failed!
at org.robolectric.shadows.ShadowActivity.getWindow(ShadowActivity.java:329)
at org.robolectric.shadows.ShadowActivity.findViewById(ShadowActivity.java:275)
at android.app.Activity.findViewById(Activity.java)
at MainActivityTest.shouldNotBeNull(MainActivityTest.java:32)
    (...)
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import static org.fest.assertions.api.ANDROID.assertThat;


import android.widget.Button;
import android.widget.EditText;


import com.abs.databaseprototype.MainActivity;
import com.abs.databaseprototype.R;

@RunWith(RobolectricTestRunner.class)
public class MainActivityTest {
private MainActivity activity;

@Before
public void setup() {
  activity = Robolectric.buildActivity(MainActivity.class).get();
}
@Test
public void shouldNotBeNull() {
  assertThat(activity).isNotNull();

  Button btnPatients = (Button) activity.findViewById(R.id.btnPatients);
  assertThat(btnPatients).isNotNull();
//
//    Button btnSpecialties = (Button) activity.findViewById(R.id.btnSpecialites);
// …
Run Code Online (Sandbox Code Playgroud)

eclipse testing android robolectric

2
推荐指数
1
解决办法
1287
查看次数