Parser 의 bind

Programming/Haskell 2015. 5. 15. 18:28

결론부터 이야기하자면, 잘 모르겠다. 

잘 모르겠으나 최대한 이해해 보려고 하는 차원에서 조금씩 뜯어보아 정리했다. 


여기서 bind ( >>= ) 는 시그니쳐를 풀어보면 a 타입의 parser 를 첫번째 인자로, a 타입을 인자로 해서 b 타입의 parser 로 변환하는 함수를 두번째 인자로해서 b 타입의 parser 를 리턴한다. 


정의를 살펴보면, .parse p inp 의 파싱이 성공한 경우 그 결과에 f 를 적용하여 Parser b 타입으로 ( 즉, b 타입을 파싱할 수 있는 함수 ) 변경하고, 이를 out 에 적용한다. ( 즉, out 으로부터 b 타입의 파싱을 시도한다 )


'Programming > Haskell' 카테고리의 다른 글

IO Type  (0) 2015.05.20
Parser in Haskell  (0) 2015.05.18

Unity3d 플러그인 - managed plugins

Mobile Programming/Unity3d 2015. 4. 20. 20:43

plugin

managed plugins

http://docs.unity3d.com/Manual/UsingDLL.html

dll 로 외부 컴파일러로 빌드, 스크립트를 컴파일 하는 것도 가능. 프로젝트에 추가되어 어떤 다른 오브젝트든, 보통 스크립트처럼 사용 가능하다.

  • Unity 에서 제공하지 않는 언어로 개발된 바이너리 로드
  • Unity 코드를 소스제공 없이 이용할 수 있게 배포

Creating a DLL

  • .NET 코드를 생성하는 컴파일러를 선택
  • Unity API 를 사용하지 않는다면 컴파일러 옵션을 적절하게 선택하는 것만으로 DLL 을 생성
  • Unity API 를 사용한다면 Unity 자체의 DLL 을 컴파일러에서 사용가능하도록 만들어야한다.
Unity API
  1. mac

    • UnityEngine.dll / UnityEditor.dll
    • /Applications/Unity/Unity.app/Contents/Frameworks/Managed/
    • contextual menu (right click on unity) > Show Package Contents command
  2. windows

    • UnityEngine.dll / UnityEditor.dll
    • C:\Program Files\Unity\Editor\Data\Managed
  3. compile option example

    1. mcs -r:/Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll -target:library ClassesForDLL.cs
    2. -r : included library path
    3. -target : build type
    4. (path) name
Tutorial
  1. Add Reference on Unity DLL

    1. mac (MonoDevelop)

      • References > Edit References > .Net Assembly tab > File System > select file.
    2. windows

      • References > Add Reference > Browse > select file
  2. Write DLL Code

  3. Using DLL in Unity
    1. copy builded dll into asset folder
  4. Setting UP Debugging
    1. mac
      • copy mdb into Assets/Plugins
      • Add-in Manager > Installed tab > Unity > select Mono Soft Debugger Support For Unity > Enable
    2. windows
      • pdb to mdb
      • Program Files\Unity\Editor\Data\Mono\lib\mono\2.0\pdb2mdb.exe


Daytime.2 - A synchronous TCP daytime server

Programming/Boost asio 2015. 4. 19. 13:05

다음에 기반함

http://www.boost.org/doc/libs/1_57_0/doc/html/boost_asio/tutorial/tutdaytime2.html


이번엔 TCP asio 를 사용하여 어떻게 서버 응용프로그램을 구현할 수 있는지 살펴본다.

#include <ctime>
#include <iostream>
#include <string>
#include <boost/asio.hpp>

using boost::asio::ip::tcp;


클라이언트로 다시 보내줄 문자열을 생성하는 make_daytime_string() 함수를 정의해보겠다.

이 함수는 daytime 서버 응용프로그램 내에서 재사용 될 것이다.

std::string make_daytime_string()
{
  using namespace std; // For time_t, time and ctime;
  time_t now = time(0);
  return ctime(&now);
}

int main()
{
  try
  {
    boost::asio::io_service io_service;


ip::tcp::acceptor 객체는 새로운 커넥션을 listen 하기 위해 생성하였다. IPv4, TCP 포트 13 을 listen 하도록 초기화 했다. 

    tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v4(), 13));


한번에 하나의 커넥션을 다루는 iterative 서버가 될 것이다. 클라이언트의 커넥션을 표현할 socket 를 생성하고, 커넥션을 기다리도록 하자. 

 for (;;)
    {
      tcp::socket socket(io_service);
      acceptor.accept(socket);


클라이언트가 우리의 서비스에 접속했다. 현재 시간을 확인하고 클라이언트로 정보를 보낸다.

      std::string message = make_daytime_string();

      boost::system::error_code ignored_error;
      boost::asio::write(socket, boost::asio::buffer(message), ignored_error);
    }
  }


마지막으로, 예외를 처리한다. 

 catch (std::exception& e)
  {
    std::cerr << e.what() << std::endl;
  }

  return 0;
}


- full_source code



- main



- 실행결과


클라이언트바이너리를 별도로 만들어놓은 후, ( 이전 포스트 ) 서버실행후 클라이언트를 실행했다.